pandas -> json

main
L_DelOff 2024-10-27 14:04:25 +03:00
parent add6f0a970
commit a6fa9e55ca
9 changed files with 81 additions and 70 deletions

File diff suppressed because one or more lines are too long

47
channels.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,11 @@
[Server]
address = ldeloff.ru
address = mumble.ldeloff.ru
port = 64738
password =
tokens =
[Bot]
bot_name = Харон_test
certfile = harontest.pem
bot_name = Харон
certfile = haron.pem
data_folder = bot_data
userlist = userlist.ini
admins = L_DelOff;L_DelOff_m;

View File

@ -1,8 +1,8 @@
import configparser
import json
import logging
import os
from typing import List
import pandas
from src.model.MumbleChannel import MumbleChannel
@ -35,23 +35,24 @@ class BotConfig:
def load_channel_list(self):
_logger.info("Загрузка файла с настройками каналов ...")
data = pandas.read_csv('channels.csv', delimiter=";")
data = data.reset_index()
for index, row in data.iterrows():
self.channelList.append(MumbleChannel(row['path'], row['message']))
try:
with open("channels.json", encoding="utf-8") as f:
data = json.load(f)
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("Файл с настройками каналов загружен")
except FileNotFoundError:
_logger.error("Файл channels.json не найден")
except json.JSONDecodeError:
_logger.error("Ошибка в формате JSON файла channels.json")
def load_welcome_message(self) -> str:
_logger.info("Загрузка файла с приветствием ...")
f = open('welcome.csv', 'r', encoding='utf-8')
message = f.read()
f.close()
return message
# bot = BotConfig()
# config = bot.config
# adminList = bot.adminList
# userList = bot.userList
#for ch in bot.channelList:
# print(ch.__str__())
for channel in self.channelList:
if channel.name == "root":
_logger.info("Приветственное сообщение загружено")
return channel.message
_logger.warning("Приветственное сообщение не найдено загружено")
return ""

View File

@ -3,10 +3,10 @@ class MumbleChannel:
path: str
message: str
def __init__(self, path: str, message: str):
def __init__(self, name: str, path: str, message: str):
self.path = path
self.message = message
self.name = path.split('/')[-1]
self.name = name
def __str__(self) -> str:
string = f"MumbleChannel:\n name: {self.name} \n path: {self.path} \n message: {self.message}"

View File

@ -16,6 +16,8 @@ class ChannelService:
self.bot_data.config.load_channel_list()
channels = self.bot_data.config.channelList
for channel in channels:
if channel.name == 'root':
continue
parent_channel_id = 0
path_split = channel.path.split('/')
for path in path_split:

View File

@ -1,6 +1,4 @@
import logging
from concurrent.futures import ThreadPoolExecutor, TimeoutError as FutureTimeoutError
from concurrent.futures import ThreadPoolExecutor
from typing import Optional
from pymumble_py3.users import User, Users
@ -58,10 +56,13 @@ class MumbleBotService:
# TODO: одинаковые каналы (коллизия сообщений)
def user_change_channel(self, user: User, action):
try:
_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'])
if len(message) > 0:
self.get_user_by_session(user['session']).send_text_message(message)
except KeyError:
return
def user_connect_server(self, action):
user = self.get_user_by_session(action['session'])

File diff suppressed because one or more lines are too long