def get_youtube(parameters): if len(parameters ) == 4 and parameters[1] == 'add' and functions_bot.check_link( parameters[2], var.yt_link): if functions_bot.name_of_obj_already_exist(parameters[3], var.yt_vids): return 'The name already exist' var.yt_vids.append(yt_vid.Video(parameters[2], parameters[3])) InputOutputJSON.write_json_file(var.yt_vids, var.yt_vids_file) return 'Successfully added' if len(parameters) == 1 and len(var.yt_vids) > 0: video = var.yt_vids[random.randint(0, len(var.yt_vids) - 1)] return f'Name: {video.name}\n{video.link}' if len(parameters) == 2 and parameters[1] == 'list': names = '' for obj in var.yt_vids: names += f'{obj.name}\n' return names if len(parameters) == 2: for obj in var.yt_vids: if parameters[1] == obj.name: return obj.link return "Link not founded" else: return 'Something went wrong!'
def make_important_message(parameters): if parameters[1] == 'clear' and len(parameters) == 2: var.important_messages = [] InputOutputJSON.write_json_file([], var.important_messages_file, True) return 'Alle wichtigen Nachrichten wurden gelöscht' elif parameters[1] == 'print' and len(parameters) == 2: text = '' for obj in var.important_messages: text += f'{obj.user} schrieb: "{str(obj.message)}" in {obj.channel}\n' if text == '': text = 'Keine Nachrichten vorhanden' return text else: message = parameters[0] var.important_messages.append( important_message.ImportantMessage( str(message.content)[3:len(message.content)], str(message.channel), str(message.author))) InputOutputJSON.write_json_file(var.important_messages, var.important_messages_file) return ''
async def on_message(self, message): if message.author == client.user: return if not functions_bot.check_if_user_register(str(message.author), var.users): var.users.append(functions_bot.create_user(message.author)) InputOutputJSON.write_json_file(var.users, users_file) if message.content.startswith('.') or message.content.startswith('.@'): bot_message = '' result = '' command = functions_bot.get_command_from_content(message.content) parameter_list = functions_bot.get_parameter_list( message.content, message) print(parameter_list) if command in comHandler: function = comHandler[command] result = function(parameter_list) bot_message = result if command == 'vid' and len( parameter_list) > 1 and parameter_list[1] == 'add': await message.channel.purge(limit=1) if len(bot_message): await message.channel.send(bot_message)
async def on_ready(self): print("Ich bin eingeloggt!") var.path_data = str(__file__)[0:len(__file__) - 12] + 'data/' if not os.path.exists(var.path_data + var.users_file): with open(var.path_data + var.users_file, 'w'): pass if not os.path.exists(var.path_data + var.important_messages_file): with open(var.path_data + var.important_messages_file, 'w'): pass if not os.path.exists(var.path_data + var.yt_vids_file): with open(var.path_data + var.yt_vids_file, 'w'): pass if not os.path.exists((var.path_data + var.msgs_file)): with open(var.path_data + var.msgs_file, 'w'): pass if not os.path.exists((var.path_data + var.quotes_file)): with open(var.path_data + var.quotes_file, 'w'): pass var.important_messages = functions_bot.convert_dict_in_obj_list( InputOutputJSON.read_json_file(important_messages_file), 'important_message') var.users = functions_bot.convert_dict_in_obj_list( InputOutputJSON.read_json_file(users_file), 'user') var.yt_vids = functions_bot.convert_dict_in_obj_list( InputOutputJSON.read_json_file(var.yt_vids_file), 'yt_vid') var.quotes = functions_bot.convert_dict_in_obj_list( InputOutputJSON.read_json_file(var.quotes_file), 'quote') var.msgs = InputOutputJSON.read_json_file(var.msgs_file)
def get_quote(parameters): if parameters[1] == 'add' and len(parameters) == 3: current_quote = quote.Quote(str(parameters[0].author), parameters[2]) var.quotes.append(current_quote) InputOutputJSON.write_json_file(var.quotes, var.quotes_file) return "Erfolgreich hinzugefügt!" if parameters[1] == 'rand' and len(parameters) == 2: current_quote = random.choice(var.quotes) return f"{current_quote.creator} lehrte uns:" \ f"```{current_quote.quote}```" return "Something went wrong"
def handle_notes(parameters): result = '' if len(parameters) < 2: return 'There is no message or category!' current_user = functions_bot.get_user(parameters[0].author.id) if current_user == 'ERROR': return 'User not found' if parameters[1] == 'info': result = functions_bot.info_msg_dir(current_user) if parameters[1] == 'titles': result = functions_bot.get_titles(current_user) if parameters[1] == 'note': cat_string = functions_bot.cut_parameters_from_command( str(parameters[0].content)) cat = functions_bot.cut_decisions(cat_string)[1:] result = functions_bot.get_note(cat[0], current_user) if parameters[1] == 'new' and parameters[2] == 'cat': cat_string = functions_bot.cut_parameters_from_command( str(parameters[0].content)) cat = functions_bot.cut_decisions(cat_string)[2:] if len(cat) != 1: return 'Something went wrong' if '/' in cat[0]: return 'Keine / in Namen!' result = functions_bot.create_category(cat[0], current_user) if parameters[1] == 'del' and parameters[2] == 'cat': cat_string = functions_bot.cut_parameters_from_command( str(parameters[0].content)) cat = functions_bot.cut_decisions(cat_string)[2:] if len(cat) != 1: return 'Something went wrong' result = functions_bot.delete_category(cat[0], current_user) if parameters[1] == 'new' and parameters[2] == 'msg': msg_string = functions_bot.cut_parameters_from_command( str(parameters[0].content)) msg = functions_bot.cut_decisions(msg_string)[2:] if len(msg) != 2: return 'Something went wrong' result = functions_bot.create_msg(msg[0], msg[1], current_user) if parameters[1] == 'del' and parameters[2] == 'msg': msg_string = functions_bot.cut_parameters_from_command( str(parameters[0].content)) msg = functions_bot.cut_decisions(msg_string)[2:] if len(msg) != 1: return 'Something went wrong' result = functions_bot.delete_msg(msg[0], current_user) if parameters[1] == 'purge': var.msgs = {} functions_bot.set_cursor_to_begin() return 'Alle Notizen und Kategorien wurden gesäubert!' if parameters[1] == 'cd': cat_string = functions_bot.cut_parameters_from_command( str(parameters[0].content)) cat = functions_bot.cut_decisions(cat_string)[1:] if len(cat) != 1: return 'Something went wrong' result = functions_bot.set_user_cursor(cat[0], current_user) InputOutputJSON.write_json_file(var.msgs, var.msgs_file) InputOutputJSON.write_json_file(var.users, var.users_file) return result