diff --git a/discord_bot/bot_d.py b/discord_bot/bot_d.py index e0eb6e8..2b77095 100644 --- a/discord_bot/bot_d.py +++ b/discord_bot/bot_d.py @@ -349,8 +349,11 @@ async def on_message(message): # print(guild) cursor.executemany("INSERT OR REPLACE INTO bot_data VALUES(?, ?)", bot_data) connection.commit() - if guild_result[12] == "Enabled": + try: + if guild_result[12] == "Enabled": await message_to_xp(bot, discord, message, botconfig, platform, os, datetime, one_result, guild_result, localization, unix_time_millis, embed_color, connection, cursor, prefix) + except: + pass timingcount = 0 if message.content.startswith(botconfig['prefix']) or message.content.startswith(guild_result[6]): @@ -404,11 +407,11 @@ async def on_message(message): if message.content.startswith(botconfig['prefix'] + 'profile') or message.content.startswith(guild_result[6] + 'profile'): args = message.content.split(); try: - if args[1] == "-u": + if args[1] == "-u": await profile.get_user(bot, discord, message, botconfig, platform, os, datetime, one_result, localization, args, unix_time_millis, connection, cursor, intents, lastmsgtime, embed_color) - if args[1] == "-g": + if args[1] == "-g": await profile.get_guild(bot, discord, message, botconfig, platform, os, datetime, one_result, localization, args, unix_time_millis, connection, cursor, guild_result, intents, embed_color) - else: + else: pass except Exception as e: print(e) diff --git a/discord_bot/bot_s.py b/discord_bot/bot_s.py new file mode 100644 index 0000000..3a7e0f5 --- /dev/null +++ b/discord_bot/bot_s.py @@ -0,0 +1,35 @@ +import discord +import platform +import os +import keep_alive +import requests + +bot = discord.Client() + +from .discord_botconfig import botconfig + +@bot.event +async def on_ready(): + keep_alive.keep_alive() + print('\nWelcome! Vision ver. ' + botconfig['version'] + '\n(©) 2020-2021 Tinelix. All rights reserved.') + print('\nConnected - ' + bot.user.name + '#' + bot.user.discriminator + '\nLatency: ' + str(round(bot.latency * 1000, 2)) + ' ms | Guilds: ' + str(len(bot.guilds))) + print('----------------------------------------------------------------------') + boticord_token = os.environ['BOTICORDTOKEN'] + bots_ds_token = os.environ['BOTSDST'] + game = discord.Game(str("Something went wrong..."), type=discord.ActivityType.watching) + await bot.change_presence(status=discord.Status.dnd, activity=game) + res = requests.post("https://api.server-discord.com/v2/bots/785383439196487720/stats", headers={'Content-Type':'application/json', + 'Authorization': 'SDC {0}'.format(bots_ds_token)}, json={'shards': 0, 'servers': len(bot.guilds)}) + print(res.content.decode('utf-8')) + res2 = requests.post("https://boticord.top/api/stats", headers={'Content-Type':'application/json', + 'Authorization': '{}'.format(boticord_token)}, json={'shards': 0, 'servers': len(bot.guilds), 'users': len(bot.users)}) + print(res2.content.decode('utf-8')) + +@bot.event +async def on_message(message): + if message.content.startswith(botconfig['prefix']): + text = 'В работе бота произошли технические неполадки, мы разберемся с ними. А чтобы не скучать, заходите на наш [саппорт-сервер](https://discord.gg/HAt6K2QuJU) или воспользуйтесь [тестируемой версии бота](https://discord.com/oauth2/authorize?client_id=769515555765616690&permissions=8&scope=bot).\n\n**Приносим свои извинения за доставленные неудобства!**' + information = discord.Embed(title="Важная информация!", description=text, color=botconfig['accent2']) + await message.channel.send(embed=information) + +bot.run(botconfig['token']) \ No newline at end of file diff --git a/discord_bot/d_commands/help.py b/discord_bot/d_commands/help.py index 1d75d51..9c4f295 100644 --- a/discord_bot/d_commands/help.py +++ b/discord_bot/d_commands/help.py @@ -8,10 +8,16 @@ async def help_cmd(bot, discord, message, botconfig, platform, os, datetime, one 'Все наши ссылки находятся в `info`?', 'Узнать погоду можно в `weather`?', 'Просмотреть рандомные фото можно в `photo`? Вдруг пригодится поставить обои на свой рабочий стол?', - 'Что в версии 01R5 (9 января 2020 г.) появилась команда `codec` для зашифровки и расшифровки текста?' + 'Начиная с версии VisionOne 01R8 (21 января 2021 г.), стало возможным менять префиксы, получать опыты за сообщения и т.д?', + 'Игра "Магический шар" генерирует случайные ответы трех типов (да/нет/хз) для заданного вопроса? Обратите внимание, что совпадения случайны, поэтому воспринимайте как игру, а не как реальность.', + 'Автор {0} (`{1}`) начал строить своего предшественника под названием Highflash в декабре 2018 г. на discord.js (JavaScript).'.format(botconfig['name'], bot.get_user(int(botconfig['owner'])).name + "#" + str(bot.get_user(int(botconfig['owner'])).discriminator)) ] else: - tips = ['All our links on `info` command'] + tips = [ + 'All our links on `info` command', + 'Starting with VisionOne 01R8 (January 21, 2021), has it become possible to change prefixes, get experiences for messages, etc?', + 'Author {0} (`{1}`) started building his predecessor called Dmitryev Bot (now Highflash) in December 2018 on discord.js (JavaScript).'.format(botconfig['name'], bot.get_user(int(botconfig['owner'])).name + "#" + str(bot.get_user(int(botconfig['owner'])).discriminator)) + ] try: if guild_result[6] == botconfig['prefix']: custom_prefix = "" diff --git a/discord_bot/d_commands/profile.py b/discord_bot/d_commands/profile.py index 254cf7f..e360871 100644 --- a/discord_bot/d_commands/profile.py +++ b/discord_bot/d_commands/profile.py @@ -17,9 +17,9 @@ async def get_user(bot, discord, message, botconfig, platform, os, datetime, a_user = message.author try: argsuser = [(a_user.id, 'Russian', 0, 10800000, - unix_time_millis(message.created_at), 'Disabled', 0)] + unix_time_millis(message.created_at), 'Disabled', unix_time_millis(message.created_at), "Disabled", unix_time_millis(message.created_at), 0, 0, 0)] cursor.executemany( - "INSERT OR IGNORE INTO users VALUES(?, ?, ?, ?, ?, ?, ?);", + "INSERT OR IGNORE INTO users VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", argsuser) connection.commit() except: @@ -32,12 +32,14 @@ async def get_user(bot, discord, message, botconfig, platform, os, datetime, nick = "_Отсутствует_" else: nick = a_user.nick - result = cursor.execute("SELECT * FROM users WHERE userid = " + - str(a_user.id) + ";").fetchone() - if result[5] == "Disabled": + result = cursor.execute("SELECT * FROM users WHERE userid = " + str(a_user.id) + ";").fetchone(); + try: + if result[5] == "Disabled": + msgcounter = localization[1][3][6] + else: + msgcounter = str(result[2]) + str(localization[1][3][5]) + except: msgcounter = localization[1][3][6] - else: - msgcounter = str(result[2]) + str(localization[1][3][5]) if a_user.raw_status == "online": user_status = localization[1][3][11][0] if a_user.raw_status == "idle": @@ -46,26 +48,32 @@ async def get_user(bot, discord, message, botconfig, platform, os, datetime, user_status = localization[1][3][11][2] if a_user.raw_status == "offline": user_status = localization[1][3][11][3] - joindate_ms = int(unix_time_millis(a_user.joined_at) + one_result[3]) - joindate = datetime.datetime.fromtimestamp( - (joindate_ms) / 1000) # 25200000 for UTC+7 - regdate_ms = int(unix_time_millis(a_user.created_at) + one_result[3]) - regdate = datetime.datetime.fromtimestamp( - (regdate_ms) / 1000) # 25200000 for UTC+7 + try: + joindate_ms = int(unix_time_millis(a_user.joined_at) + one_result[3]) + joindate = datetime.datetime.fromtimestamp( + (joindate_ms) / 1000) # 25200000 for UTC+7 + regdate_ms = int(unix_time_millis(a_user.created_at) + one_result[3]) + regdate = datetime.datetime.fromtimestamp( + (regdate_ms) / 1000) # 25200000 for UTC+7 + except: + pass try: if a_user.id == message.author.id: prepostdate_ms = int(lastmsgtime + one_result[3]) else: prepostdate_ms = int(result[6] + one_result[3]) except: - prepostdate_ms = 0 + pass try: prepostdate = datetime.datetime.fromtimestamp( (prepostdate_ms) / 1000) # 25200000 for UTC+7 except: pass - dbregdate_ms = result[4] - dbregdate = datetime.datetime.fromtimestamp(dbregdate_ms / 1000) + try: + dbregdate_ms = result[4] + dbregdate = datetime.datetime.fromtimestamp(dbregdate_ms / 1000) + except: + pass member_roles_a = "" for member_roles in a_user.roles: if member_roles.name != "@everyone": @@ -77,18 +85,25 @@ async def get_user(bot, discord, message, botconfig, platform, os, datetime, member_roles_a += "" if member_roles_a == "" or member_roles_a == None: member_roles_a = "_Нет_" + try: + rep = "\n**" + str(localization[1][3][14]) + ": **" + str(one_result[7]) + except: + rep = "" userprofile_content = discord.Embed( title=bot_detector + str(localization[1][3][0]) + str(a_user), - description="**ID: **" + str(a_user.id) + "\n**" + str(localization[1][3][14] + ": **" + str(one_result[7])), + description="**ID: **" + str(a_user.id) + rep, color=embed_color) userprofile_content.add_field( name=str(localization[1][3][1]), value=str(nick), inline=True) userprofile_content.add_field( name=str(localization[1][3][10]), value=user_status, inline=False) - userprofile_content.add_field( + try: + userprofile_content.add_field( name=str(localization[1][3][4]) + dbregdate.strftime("%Y-%m"), value=msgcounter, inline=False) + except: + pass userprofile_content.add_field( name=str(localization[1][3][2]), value=joindate.strftime("%Y-%m-%d %H:%M:%S") + " (UTC" + your_timezone @@ -98,11 +113,14 @@ async def get_user(bot, discord, message, botconfig, platform, os, datetime, url=str( a_user.avatar_url_as(format=None, static_format="jpeg", size=4096))) - userprofile_content.add_field( + try: + userprofile_content.add_field( name=str(localization[1][3][3]), value=regdate.strftime("%Y-%m-%d %H:%M:%S") + " (UTC" + your_timezone + ")", inline=False) + except: + pass try: userprofile_content.add_field( name=str(localization[1][3][12]) + "(" + @@ -123,10 +141,13 @@ async def get_user(bot, discord, message, botconfig, platform, os, datetime, except: pass if a_user.bot == False: - userprofile_content.add_field( + try: + userprofile_content.add_field( name=str(localization[1][3][15]), value="**{0}** ({1}/{2})".format(str(one_result[9]), str(one_result[8]), str(((one_result[9]) * (50 + ((one_result[9]) * 10)) * (one_result[9] + 1)))), inline=False) + except: + pass msg = await message.channel.send(embed=userprofile_content) if str(a_user.avatar_url_as( format=None, static_format="jpeg", size=4096)) != "" or str( @@ -162,7 +183,7 @@ async def on_member_update(before, after): nick = after.nick userprofile_changed = discord.Embed( title=bot_detector + str(localization[1][3][0]) + str(after), - description="**ID: **" + str(after.id), + description="**ID: **" + str(after.id) + rep, color=embed_color) userprofile_changed.add_field( name=str(localization[1][3][1]), value=str(nick), inline=True) @@ -183,11 +204,14 @@ async def on_member_update(before, after): url=str( after.avatar_url_as( format=None, static_format="jpeg", size=4096))) - userprofile_changed.add_field( + try: + userprofile_changed.add_field( name=str(localization[1][3][3]), value=regdate.strftime("%Y-%m-%d %H:%M:%S") + " (UTC" + your_timezone + ")", inline=False) + except: + pass try: userprofile_changed.add_field( name=str(localization[1][3][13]), @@ -197,10 +221,13 @@ async def on_member_update(before, after): except: pass if a_user.bot == False: - userprofile_changed.add_field( - name=str(localization[1][3][15]), - value="**{0}** ({1}/{2})".format(str(one_result[9]), str(one_result[8]), str(((one_result[9]) * (50 + ((one_result[9]) * 10)) * (one_result[9] + 1)))), - inline=False) + try: + userprofile_changed.add_field( + name=str(localization[1][3][15]), + value="**{0}** ({1}/{2})".format(str(one_result[9]), str(one_result[8]), str(((one_result[9]) * (50 + ((one_result[9]) * 10)) * (one_result[9] + 1)))), + inline=False) + except: + pass await msg.edit(embed=userprofile_changed) @bot.event diff --git a/discord_bot/d_events/new_member.py b/discord_bot/d_events/new_member.py index d464deb..a686c9f 100644 --- a/discord_bot/d_events/new_member.py +++ b/discord_bot/d_events/new_member.py @@ -15,22 +15,25 @@ async def on_reaction_add(reaction, user): await msg.edit(embed=new_member_content) async def new_member(bot, discord, member, botconfig, cursor, connection): - cursor.execute("SELECT * FROM guilds WHERE guildid='" + str(member.guild.id) + "';") - guild_result = (cursor.fetchone()) - search_results = 0 - for channel in member.guild.channels: - if channel.id == guild_result[8]: - search_results += 1 - msgtext = guild_result[9] try: - msgtext_formatted = msgtext.format(user = member.name, user_with_discrim = str(member.name) + "#" + str(member.discriminator), mention = "<@" + str(member.id) + ">") - except: - msgtext_formatted = "" - if search_results == 1 and guild_result[9] != None and guild_result[9] != "" and guild_result[9] != " " and msgtext_formatted != "": + cursor.execute("SELECT * FROM guilds WHERE guildid='" + str(member.guild.id) + "';") + guild_result = (cursor.fetchone()) + search_results = 0 + for channel in member.guild.channels: + if channel.id == guild_result[8]: + search_results += 1 + msgtext = guild_result[9] + try: + msgtext_formatted = msgtext.format(user = member.name, user_with_discrim = str(member.name) + "#" + str(member.discriminator), mention = "<@" + str(member.id) + ">") + except: + msgtext_formatted = "" + if search_results == 1 and guild_result[9] != None and guild_result[9] != "" and guild_result[9] != " " and msgtext_formatted != "": new_member_content = discord.Embed(description=msgtext_formatted, color=botconfig['accent1']) msg = await bot.get_channel(guild_result[8]).send(embed=new_member_content) - if guild_result is None: + if guild_result is None: return + except: + pass async def member_left(bot, discord, member, botconfig, cursor, connection): cursor.execute("SELECT * FROM guilds WHERE guildid='" + str(member.guild.id) + "';")