diff --git a/discord_bot/bot_d.py b/discord_bot/bot_d.py index 72ee92f..0ab7fca 100644 --- a/discord_bot/bot_d.py +++ b/discord_bot/bot_d.py @@ -11,6 +11,9 @@ import numexpr import gc import keep_alive +import cpuinfo +import psutil + keep_alive.keep_alive() from requests.auth import HTTPBasicAuth @@ -347,7 +350,7 @@ async def on_message(message): else: await help_cmd(bot, discord, message, botconfig, os, platform, datetime, one_result, en_US.get(), botconfig['accent1']) if message.content.startswith(botconfig['prefix'] + 'state'): - await state_cmd(bot, discord, sqlite3, message, botconfig, os, platform, datetime, one_result, localization, embed_color, connection, cursor) + await state_cmd(bot, discord, sqlite3, message, botconfig, os, platform, datetime, one_result, localization, embed_color, connection, cursor, cpuinfo, psutil) if message.content.startswith(botconfig['prefix'] + 'eval'): await eval_cmd(bot, discord, message, botconfig, os, platform, datetime, one_result, localization, en_US, guild_result, intents, embed_color) if message.content.startswith(botconfig['prefix'] + 'guilds'): @@ -366,9 +369,9 @@ async def on_message(message): if args[1] == "-tz": await settings.set_timezone(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis) if args[1] == "-mc": - await settings.switch_msgcounter(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis) + await settings.switch_msgcounter(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis,guild_result) if args[1] == "-ec": - await settings.set_embed_color(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis, embed_color) + await settings.set_embed_color(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis, embed_color, guild_result) if args[1] == "-welcm": await settings.set_welcome_message(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis, embed_color) if args[1] == "-byem": diff --git a/discord_bot/d_commands/help.py b/discord_bot/d_commands/help.py index 089f31f..e39a7ae 100644 --- a/discord_bot/d_commands/help.py +++ b/discord_bot/d_commands/help.py @@ -9,7 +9,8 @@ async def help_cmd(bot, discord, message, botconfig, platform, os, datetime, 'Все наши ссылки находятся в `info`?', 'Узнать погоду можно в `weather`?', 'Просмотреть рандомные фото можно в `photo`? Вдруг пригодится поставить обои на свой рабочий стол?', - 'Что в версии 01R5 (9 января 2020 г.) появилась команда `codec` для зашифровки и расшифровки текста?' + 'Что в версии 01R5 (9 января 2020 г.) появилась команда `codec` для зашифровки и расшифровки текста?', + 'Зайти на наш саппорт-сервер можно по [ссылке](https://discord.gg/HAt6K2QuJU)' ] else: tips = ['All our links on `info` command'] diff --git a/discord_bot/d_commands/set.py b/discord_bot/d_commands/set.py index 7fbc8d6..51992ba 100644 --- a/discord_bot/d_commands/set.py +++ b/discord_bot/d_commands/set.py @@ -60,7 +60,7 @@ async def set_timezone(bot, discord, message, botconfig, os, platform, datetime, timezone_content = discord.Embed(title=str(localization[1][2][3][0]), description=localization[1][2][4][2] + your_timezone, color=botconfig['accent1']) await message.channel.send(embed=timezone_content) -async def switch_msgcounter(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis): +async def switch_msgcounter(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis, guild_result): subargs = args[2] if subargs == "on": msgcounter_choice = discord.Embed(title=str(localization[1][2][5][0]), description=str(localization[1][2][5][1]), color=botconfig['accent1']) @@ -75,7 +75,7 @@ async def on_reaction_add(reaction, user): if reaction.emoji == "🏠" and user.id != bot.user.id: if message.author.guild_permissions.manage_guild == True: try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], 'Disabled', one_result[5], one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, guild_result[1], guild_result[2], guild_result[3], 'Disabled', guild_result[5], guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', 'Standart', '=', 'English', 0, '', 0, '')] cursor.executemany("INSERT OR REPLACE INTO guilds VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", guild) @@ -104,7 +104,7 @@ async def on_reaction_add(reaction, user): if reaction.emoji == "🏠" and user.id != bot.user.id: if message.author.guild_permissions.manage_guild == True: try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], 'Disabled', one_result[5], one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, guild_result[1], guild_result[2], guild_result[3], 'Disabled', guild_result[5], guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Disabled', "Standart", "=", 'English', 0, '', 0, '')] cursor.executemany("INSERT OR REPLACE INTO guilds VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", guild) @@ -123,7 +123,7 @@ async def on_reaction_add(reaction, user): if subargs != "off" and subargs != "on": await settings_cmd(bot, discord, message, botconfig, os, platform, datetime, one_result) -async def set_embed_color(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis, embed_color): +async def set_embed_color(bot, discord, message, botconfig, os, platform, datetime, one_result, args, connection, cursor, localization, unix_time_millis, embed_color, guild_result): subargs = args[2] nopermerr_content = discord.Embed(title=str(localization[1][2][5][5]), description=str(localization[1][2][5][4]), color=botconfig['accent2']) @@ -131,42 +131,42 @@ async def set_embed_color(bot, discord, message, botconfig, os, platform, dateti if subargs == "red": try: print('test') - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Red", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Red", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Red", "=", 'English', 0, '', 0, '')] if subargs == "orange": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Standart", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Standart", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Standart", "=", 'English', 0, '', 0, '')] if subargs == "yellow": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Yellow", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Yellow", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Yellow", "=", 'English', 0, '', 0, '')] if subargs == "green": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Green", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Green", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Green", "=", 'English', 0, '', 0, '')] if subargs == "skyblue": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Sky-blue", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Sky-blue", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Sky-blue", "=", 'English', 0, '', 0, '')] if subargs == "blue": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Blue", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Blue", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Blue", "=", 'English', 0, '', 0, '')] if subargs == "violet": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Violet", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Violet", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Violet", "=", 'English', 0, '', 0, '')] if subargs == "rose": try: - guild = [(message.guild.id, one_result[1], one_result[2], one_result[3], one_result[4], "Rose", one_result[6], one_result[7], one_result[8], one_result[9], one_result[10], one_result[11])] + guild = [(message.guild.id, one_result[1], guild_result[2], guild_result[3], guild_result[4], "Rose", guild_result[6], guild_result[7], guild_result[8], guild_result[9], guild_result[10], guild_result[11])] except: guild = [(message.guild.id, str(message.guild.region), 1, unix_time_millis(message.created_at), 'Enabled', "Rose", "=", 'English', 0, '', 0, '')] try: diff --git a/discord_bot/d_commands/state.py b/discord_bot/d_commands/state.py index 6f89ed5..8de3f19 100644 --- a/discord_bot/d_commands/state.py +++ b/discord_bot/d_commands/state.py @@ -1,12 +1,36 @@ -async def state_cmd(bot, discord, sqlite3, message, botconfig, os, platform, datetime, one_result, localization, embed_color, connection, cursor): +async def state_cmd(bot, discord, sqlite3, message, botconfig, os, platform, datetime, one_result, localization, embed_color, connection, cursor, cpuinfo, psutil): + data_collecting_content = discord.Embed(title=str(localization[1][1][0]), description="**" + str(localization[1][1][1]) + ":** " + str(round(bot.latency * 1000, 2)) + str(localization[1][1][2]) + "\n\n" + str(localization[1][1][18]), color=embed_color) + msg = await message.channel.send(embed=data_collecting_content) usersdb = cursor.execute('SELECT * FROM users').rowcount usersdb_count = cursor.fetchall() - state_content = discord.Embed(title=str(localization[1][1][0]), color=embed_color, inline=True) - state_content.add_field(name=str(localization[1][1][1]), value=str(round(bot.latency * 1000, 2)) + str(localization[1][1][2]), inline=True) - state_content.add_field(name=str(localization[1][1][3]), value=platform.uname()[0] + " " + platform.uname()[2] + " (" + platform.uname()[3] + ")", inline=True) - state_content.add_field(name=str(localization[1][1][4]), value=platform.processor(), inline=True) + guildsdb = cursor.execute('SELECT * FROM guilds').rowcount + guildsdb_count = cursor.fetchall() + if cpuinfo.get_cpu_info()['count'] < 2: + cores_amount = str(cpuinfo.get_cpu_info()['count']) + localization[1][1][9] + elif cpuinfo.get_cpu_info()['count'] < 5: + cores_amount = str(cpuinfo.get_cpu_info()['count']) + localization[1][1][10] + else: + cores_amount = str(cpuinfo.get_cpu_info()['count']) + localization[1][1][11] + + if psutil.virtual_memory().available < 1024: + ram_available = str(round(psutil.virtual_memory().available / 1024, 2)) + localization[1][1][14] + localization[1][1][17] + elif psutil.virtual_memory().available < 1048576 and psutil.virtual_memory().available >= 1024: + ram_available = str(round(psutil.virtual_memory().available / 1024 / 1024, 2)) + localization[1][1][15] + localization[1][1][17] + else: + ram_available = str(round(psutil.virtual_memory().available / 1024 / 1024 / 1024, 2)) + localization[1][1][16] + localization[1][1][17] + + if psutil.virtual_memory().total < 1024: + ram_total = str(round(psutil.virtual_memory().total / 1024, 2)) + localization[1][1][14] + elif psutil.virtual_memory().total < 1048576 and psutil.virtual_memory().total >= 1024: + ram_total = str(round(psutil.virtual_memory().total / 1024 / 1024, 2)) + localization[1][1][15] + else: + ram_total = str(round(psutil.virtual_memory().total / 1024 / 1024 / 1024, 2)) + localization[1][1][16] + state_content = discord.Embed(title=str(localization[1][1][0]), description="**" + str(localization[1][1][1]) + ":** " + str(round(bot.latency * 1000, 2)) + str(localization[1][1][2]), color=embed_color) + state_content.add_field(name=str(localization[1][1][3]), value=platform.uname()[0] + " " + platform.uname()[2] + " (" + platform.uname()[3] + ")", inline=False) + state_content.add_field(name=str(localization[1][1][4]), value=str(cpuinfo.get_cpu_info()['brand_raw']) + " (" + cores_amount + ", " + str(round(cpuinfo.get_cpu_info()['hz_advertised'][0] / 1000000, 2)) + localization[1][1][12] + ")", inline=False) + state_content.add_field(name=str(localization[1][1][13]), value=ram_available + " / " + ram_total, inline=True) state_content.add_field(name=str(localization[1][1][5]), value=platform.python_version(), inline=True) state_content.add_field(name=str(localization[1][1][6]), value=platform.python_build()[1], inline=True) state_content.add_field(name=str(localization[1][1][7]), value="**discord.py:** " + discord.__version__ + "\n**SQLite3 library:** " + sqlite3.sqlite_version + "\n**Vision bot:** " + botconfig['version'], inline=True) - state_content.add_field(name=str(localization[1][1][8]), value="🏠 " + str(len(bot.guilds)) + " | 👥 " + str(len(bot.users)) + " | 🗃 " + str(len(usersdb_count)), inline=True) - await message.channel.send(embed=state_content) \ No newline at end of file + state_content.add_field(name=str(localization[1][1][8]), value="🏠 " + str(len(bot.guilds)) + " | 👥 " + str(len(bot.users)) + " | 🗃 " + str(len(usersdb_count) + len(guildsdb_count)), inline=True) + await msg.edit(embed=state_content) \ No newline at end of file diff --git a/discord_bot/d_languages/en_US.py b/discord_bot/d_languages/en_US.py index f695954..934ad54 100644 --- a/discord_bot/d_languages/en_US.py +++ b/discord_bot/d_languages/en_US.py @@ -12,15 +12,15 @@ def get(): ' - simple and slightly extensible. Developed by Tinelix.\n**Prefix:** `{0}`\n\n**Did you know that...** {1}', # 1.0.0 [ # 1.0.1 'General', # 1.0.1.0 - '`help` `state` `profile` `feedback` `info`' # 1.0.1.1 + '`help`, `state`, `profile`, `feedback`, `info`' # 1.0.1.1 ], [ # 1.0.2 'Fun', # 1.0.2.0 - '`=photo`' # 1.0.2.1 + '`photo`, `8ball` (`crystball`)' # 1.0.2.1 ], [ # 1.0.3 'Management', # 1.0.3.0 - '`=settings`' # 1.0.3.1 + '`settings`, `post`' # 1.0.3.1 ], [ # 1.0.4 'Miscellaneous', # 1.0.4.0 @@ -38,8 +38,16 @@ def get(): 'Python build date', # 1.1.6 'Packages versions', # 1.1.7 'Analytics', # 1.1.8 - 'Bot author', # 1.1.9 - 'Links' # 1.1.10 + ' core', # 1.1.9 + ' cores', # 1.1.10 + ' cores', # 1.1.11 + ' MHz', # 1.1.12 + 'RAM', # 1.1.13 + ' kB', # 1.1.14 + ' MB', # 1.1.15 + ' GB', # 1.1.16 + ' free', # 1.1.17 + 'Data collection in progress as it may take time.' # 1.1.18 ], [ # 1.2 'Settings', # 1.2.0 @@ -249,10 +257,10 @@ def get(): '{0} is a simple and extensible bot from Tinelix. This bot is a replacement for the Highflash bot, which was crude enough to run for monitoring bots. But don\'t worry, the Vision bot has (albeit imperfect) integration with the SQlite3 database, when there was only primitive JSON in Highflash. The bot was written from scratch and took into account the mistakes made during the development of the Highflash bot. It develops not only thanks to you, but also to the author (Tinelix) with its productivity. He can ask you the weather, encrypt or decrypt texts, show random and rather interesting photos from Reddit and Unsplash, play Crystal Ball, etc.'.format(name), # 1.15.1 'Written in', # 1.15.2 'Author', # 1.15.3 - 'Bots Monitoring', # 1.15.4 - '[bots.server-discord.com](https://bots.server-discord.com/785383439196487720)\n[BotiCord](https://boticord.top/bot/785383439196487720)\n[Bots for Discord](https://botsfordiscord.com/bot/785383439196487720)', # 1.15.5 + 'Bots Monitorings', # 1.15.4 + '[bots.server-discord.com](https://bots.server-discord.com/785383439196487720)\n[BotiCord](https://boticord.top/bot/785383439196487720)\n[Bots for Discord](https://botsfordiscord.com/bot/785383439196487720)\n[top.gg](https://top.gg/bot/785383439196487720)', # 1.15.5 'Links', # 1.15.6 - '[Invite](https://discord.com/api/oauth2/authorize?client_id=785383439196487720&permissions=8&scope=bot)\n[GitHub](https://github.com/tinelix/visionbot)' # 1.15.7 + '[Invite](https://discord.com/api/oauth2/authorize?client_id=785383439196487720&permissions=8&scope=bot)\n[GitHub](https://github.com/tinelix/visionbot)\n[Our support server](https://discord.gg/HAt6K2QuJU)' # 1.15.7 ], [ # 1.16 'Polling', # 1.16.0 diff --git a/discord_bot/d_languages/ru_RU.py b/discord_bot/d_languages/ru_RU.py index ff4830f..832ecce 100644 --- a/discord_bot/d_languages/ru_RU.py +++ b/discord_bot/d_languages/ru_RU.py @@ -39,8 +39,16 @@ def get(): 'Дата сборки Python', 'Версии пакетов', 'Аналитика', - 'Автор бота', - 'Ссылки', + ' ядро', + ' ядра', + ' ядер', + ' МГц', + 'Оперативная память', + ' кБ', + ' МБ', + ' ГБ', + ' свободно', + 'Идет сбор данных, так как это может занимать время.' ], [ 'Настройки', @@ -236,7 +244,7 @@ def get(): 'Вы должны обязательно включить функции сообщества на Вашем Discord-сервере для публикации новостей.', # 1.13.1 'Вы забыли указать сообщение для публикации.', # 1.13.2 'Команда недоступна, так как у Вас недостаточно прав на управление сообщениями.', - 'Сначала переключитесь на новостной канал.' + 'Сначала переключитесь на новостной канал.\n\n**Инфа для креаторов:** Новостные каналы - это и есть каналы с объявлениями, но чтобы постить сообщения, Вам нужно обязательно в настройках канала (не путать с настройками сервера!) поставить галочку в пункте "Канал с объявлениями". Текст этого пункта может отличаться в зависимости от Вашей установленной локализации клиента.' ], [ # 1.14 'Кодек', # 1.14.0 @@ -255,9 +263,9 @@ def get(): 'Написан на', # 1.15.2 'Автор', # 1.15.3 'Мониторинги ботов', # 1.15.4 - '[bots.server-discord.com](https://bots.server-discord.com/785383439196487720)\n[BotiCord](https://boticord.top/bot/785383439196487720)\n[Bots for Discord](https://botsfordiscord.com/bot/785383439196487720)', # 1.15.5 + '[bots.server-discord.com](https://bots.server-discord.com/785383439196487720)\n[BotiCord](https://boticord.top/bot/785383439196487720)\n[Bots for Discord](https://botsfordiscord.com/bot/785383439196487720)\n[top.gg](https://top.gg/bot/785383439196487720)', # 1.15.5 'Ссылки', # 1.15.5 - '[Пригласить бота](https://discord.com/api/oauth2/authorize?client_id=785383439196487720&permissions=8&scope=bot)\n[GitHub](https://github.com/tinelix/visionbot)\n[ВКонтакте](https://vk.com/tinelix)\n[YouTube](https://www.youtube.com/channel/UCSPjn_Y0pLdPy6Ncb9NAdww)\n[Сервер в Discord](https://discord.gg/fYRjHvXntj)' # 1.15.6 + '[Пригласить бота](https://discord.com/api/oauth2/authorize?client_id=785383439196487720&permissions=8&scope=bot)\n[GitHub](https://github.com/tinelix/visionbot)\n[ВКонтакте](https://vk.com/tinelix)\n[YouTube](https://www.youtube.com/channel/UCSPjn_Y0pLdPy6Ncb9NAdww)\n[Сервер в Discord](https://discord.gg/fYRjHvXntj)\n[Наш саппорт-сервер](https://discord.gg/HAt6K2QuJU)' # 1.15.6 ], [ # 1.16 'Голосование', # 1.16.0 diff --git a/discord_bot/discord_botconfig.py b/discord_bot/discord_botconfig.py index f807910..5557048 100644 --- a/discord_bot/discord_botconfig.py +++ b/discord_bot/discord_botconfig.py @@ -12,7 +12,7 @@ 'accent1': 0xd7832a, 'accent2': 0xcb3532, 'accent3': 0x6eda5f, - 'version': '01R7-210113', + 'version': '01R7-210118', 'owner': '741883312108339231', 'logs_channel': 788723868255649832, 'unsplash_ak': os.environ['UNSAKEY'], diff --git a/discord_bot/mem.py b/discord_bot/mem.py new file mode 100644 index 0000000..e548208 --- /dev/null +++ b/discord_bot/mem.py @@ -0,0 +1,15 @@ +import sys, gc +def create_cycle(): + list = [8, 9, 10] + list.append(list) +def main(): + print("Creating garbage...") + for i in range(8): + create_cycle() + print("Collecting...") + n = gc.collect() + print("Number of unreachable objects collected by GC:", n) + print("Uncollectable garbage:", gc.garbage) +if __name__ == "__main__": + main() + sys.exit() \ No newline at end of file