pandas -> json
parent
add6f0a970
commit
a6fa9e55ca
39
channels.csv
39
channels.csv
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,11 @@
|
||||||
[Server]
|
[Server]
|
||||||
address = ldeloff.ru
|
address = mumble.ldeloff.ru
|
||||||
port = 64738
|
port = 64738
|
||||||
password =
|
password =
|
||||||
tokens =
|
tokens =
|
||||||
[Bot]
|
[Bot]
|
||||||
bot_name = Харон_test
|
bot_name = Харон
|
||||||
certfile = harontest.pem
|
certfile = haron.pem
|
||||||
data_folder = bot_data
|
data_folder = bot_data
|
||||||
userlist = userlist.ini
|
userlist = userlist.ini
|
||||||
admins = L_DelOff;L_DelOff_m;
|
admins = L_DelOff;L_DelOff_m;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import configparser
|
import configparser
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import List
|
from typing import List
|
||||||
import pandas
|
|
||||||
|
|
||||||
from src.model.MumbleChannel import MumbleChannel
|
from src.model.MumbleChannel import MumbleChannel
|
||||||
|
|
||||||
|
@ -35,23 +35,24 @@ class BotConfig:
|
||||||
|
|
||||||
def load_channel_list(self):
|
def load_channel_list(self):
|
||||||
_logger.info("Загрузка файла с настройками каналов ...")
|
_logger.info("Загрузка файла с настройками каналов ...")
|
||||||
data = pandas.read_csv('channels.csv', delimiter=";")
|
try:
|
||||||
data = data.reset_index()
|
with open("channels.json", encoding="utf-8") as f:
|
||||||
for index, row in data.iterrows():
|
data = json.load(f)
|
||||||
self.channelList.append(MumbleChannel(row['path'], row['message']))
|
for item in data:
|
||||||
|
if all(key in item for key in ('name', 'path', 'message')):
|
||||||
|
self.channelList.append(MumbleChannel(item['name'], item['path'], item['message']))
|
||||||
|
else:
|
||||||
|
_logger.warning(f"Пропущен элемент с недостаточными данными: {item}")
|
||||||
_logger.info("Файл с настройками каналов загружен")
|
_logger.info("Файл с настройками каналов загружен")
|
||||||
|
except FileNotFoundError:
|
||||||
|
_logger.error("Файл channels.json не найден")
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
_logger.error("Ошибка в формате JSON файла channels.json")
|
||||||
|
|
||||||
def load_welcome_message(self) -> str:
|
def load_welcome_message(self) -> str:
|
||||||
_logger.info("Загрузка файла с приветствием ...")
|
for channel in self.channelList:
|
||||||
f = open('welcome.csv', 'r', encoding='utf-8')
|
if channel.name == "root":
|
||||||
message = f.read()
|
_logger.info("Приветственное сообщение загружено")
|
||||||
f.close()
|
return channel.message
|
||||||
return message
|
_logger.warning("Приветственное сообщение не найдено загружено")
|
||||||
|
return ""
|
||||||
|
|
||||||
# bot = BotConfig()
|
|
||||||
# config = bot.config
|
|
||||||
# adminList = bot.adminList
|
|
||||||
# userList = bot.userList
|
|
||||||
#for ch in bot.channelList:
|
|
||||||
# print(ch.__str__())
|
|
||||||
|
|
|
@ -3,10 +3,10 @@ class MumbleChannel:
|
||||||
path: str
|
path: str
|
||||||
message: str
|
message: str
|
||||||
|
|
||||||
def __init__(self, path: str, message: str):
|
def __init__(self, name: str, path: str, message: str):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.message = message
|
self.message = message
|
||||||
self.name = path.split('/')[-1]
|
self.name = name
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
string = f"MumbleChannel:\n name: {self.name} \n path: {self.path} \n message: {self.message}"
|
string = f"MumbleChannel:\n name: {self.name} \n path: {self.path} \n message: {self.message}"
|
||||||
|
|
|
@ -16,6 +16,8 @@ class ChannelService:
|
||||||
self.bot_data.config.load_channel_list()
|
self.bot_data.config.load_channel_list()
|
||||||
channels = self.bot_data.config.channelList
|
channels = self.bot_data.config.channelList
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
|
if channel.name == 'root':
|
||||||
|
continue
|
||||||
parent_channel_id = 0
|
parent_channel_id = 0
|
||||||
path_split = channel.path.split('/')
|
path_split = channel.path.split('/')
|
||||||
for path in path_split:
|
for path in path_split:
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import logging
|
import logging
|
||||||
from concurrent.futures import ThreadPoolExecutor, TimeoutError as FutureTimeoutError
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from pymumble_py3.users import User, Users
|
from pymumble_py3.users import User, Users
|
||||||
|
@ -58,10 +56,13 @@ class MumbleBotService:
|
||||||
|
|
||||||
# TODO: одинаковые каналы (коллизия сообщений)
|
# TODO: одинаковые каналы (коллизия сообщений)
|
||||||
def user_change_channel(self, user: User, action):
|
def user_change_channel(self, user: User, action):
|
||||||
|
try:
|
||||||
_logger.info(f"{user['name']} перешёл в канал: {self.bot_data.bot.channels[action['channel_id']]['name']}")
|
_logger.info(f"{user['name']} перешёл в канал: {self.bot_data.bot.channels[action['channel_id']]['name']}")
|
||||||
message = self.channel_service.get_message_by_channel_id(action['channel_id'])
|
message = self.channel_service.get_message_by_channel_id(action['channel_id'])
|
||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
self.get_user_by_session(user['session']).send_text_message(message)
|
self.get_user_by_session(user['session']).send_text_message(message)
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
|
||||||
def user_connect_server(self, action):
|
def user_connect_server(self, action):
|
||||||
user = self.get_user_by_session(action['session'])
|
user = self.get_user_by_session(action['session'])
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue