From 09048b3b4ad6576770fc490cbbfb02c020b239b8 Mon Sep 17 00:00:00 2001 From: PranjalSB Date: Thu, 27 Jun 2024 00:16:07 +0530 Subject: [PATCH] OutN Upgrade -> v8 ## v8 -added commands!!! - added help command - added identify command --- CHANGELOG.md | 5 +++ README.md | 10 ++++- lib/TheOutNModule.py | 25 +++++++----- lib/catch_helper.py | 9 +---- lib/cmd_embeds.py | 65 ++++++++++++++++++++++++++++++++ lib/{makeconfig.py => config.py} | 27 +++++++++++-- lib/spawn_embeds.py | 13 +------ lib/spawn_logger.py | 9 +---- lib/star_helper.py | 10 +---- main.py | 29 ++++++++------ 10 files changed, 139 insertions(+), 63 deletions(-) create mode 100644 lib/cmd_embeds.py rename lib/{makeconfig.py => config.py} (64%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f0d85..d416a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,3 +53,8 @@ ## v7.1 - optimized code - removed useless files and parts + +## v8 +-added commands!!! + - added help command + - added identify command diff --git a/README.md b/README.md index 98848a8..8737cf0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The OutN Project -> current release : [v7.1](https://github.com/Pranjal-SB/OutN/blob/main/CHANGELOG.md) [stable](https://github.com/Pranjal-SB/OutN/releases/latest) +> current release : [v8](https://github.com/Pranjal-SB/OutN/blob/main/CHANGELOG.md) [stable](https://github.com/Pranjal-SB/OutN/releases/latest) An actively developed **Self-hostable FOSS** pokemon recognition and assistant bot for discord and made more specifically for the discord pokemon game "Poketwo". @@ -36,6 +36,7 @@ Made with ❤️ in Python - Rare and regional ping - catch logging - built-in hint solver +- both automatic & manual identification support - spawn logging - Pretty embeds - Self-hostable @@ -61,7 +62,9 @@ Made with ❤️ in Python - [x] StarBoard <- [v5.0](https://github.com/Pranjal-SB/OutN/blob/main/CHANGELOG.md#v50) - [x] catch logs <- [v6.0](https://github.com/Pranjal-SB/OutN/blob/main/CHANGELOG.md#v60) - [x] spawn logs <- [v7.0](https://github.com/Pranjal-SB/OutN/blob/main/CHANGELOG.md#v70) -- [ ] help command +- [x] commands <- [v8.0](https://github.com/Pranjal-SB/OutN/blob/main/CHANGELOG.md#v80) + - [x] help command + - [x] identify command - [ ] more.. @@ -89,6 +92,7 @@ for further usage i.e. not the first run and the dependencies are all already in you can just run 'just_run.bat' which will only run main.py and nothing else ### manual + - requires - [python](https://www.python.org/) to be installed @@ -135,6 +139,8 @@ If you have any kind of feedback or need help feel free to contact me: - Discord - [@mr.linear](https://discordapp.com/users/1140568955220656160) - [OutN support \[in development\]](https://discord.gg/aMJzFJsf) + + ## Contributing Contributions are always welcome! diff --git a/lib/TheOutNModule.py b/lib/TheOutNModule.py index f7b0a3e..b702d1f 100644 --- a/lib/TheOutNModule.py +++ b/lib/TheOutNModule.py @@ -2,14 +2,15 @@ import json import os import platform -import configparser import numpy as np from PIL import Image from io import BytesIO from tensorflow.keras.models import load_model +from config import spawnlogconfirm, starchconfirm import spawn_embeds +import cmd_embeds import preprocess_image import star_helper import spawn_logger @@ -40,14 +41,6 @@ def clear_terminal(): reg_list = file.read() -#config -config = configparser.ConfigParser() -config_file = 'config.ini' -config.read(config_file) - -spawnlogconfirm = config['CONFIRMS']['SPAWNLOGCONFIRM'] -starchconfirm = config['CONFIRMS']['STARCHCONFIRM'] - async def outnmodule(bot, message, url): async with aiohttp.ClientSession() as session: async with session.get(url=url) as resp: @@ -84,3 +77,17 @@ async def outnmodule(bot, message, url): else: await spawn_embeds.common_embed(message, name) + +async def identifycmd(message, url): + async with aiohttp.ClientSession() as session: + async with session.get(url=url) as resp: + if resp.status == 200: + content = await resp.read() + image_data = BytesIO(content) + image = Image.open(image_data) + preprocessed_image = await preprocess_image.pimg(image) + predictions = loaded_model.predict(preprocessed_image) + classes_x = np.argmax(predictions, axis=1) + name = list(classes.keys())[classes_x[0]] + await cmd_embeds.identify_embed(message, name) + diff --git a/lib/catch_helper.py b/lib/catch_helper.py index cf7c1fb..3e4c23d 100644 --- a/lib/catch_helper.py +++ b/lib/catch_helper.py @@ -1,13 +1,6 @@ -import configparser - from discord import Color, Embed -#config -config = configparser.ConfigParser() -config_file = 'config.ini' -config.read(config_file) - -clog = int(config['DEFAULT']['CLOG']) +from config import clog async def catch_identifier(bot, message): await clog_embed(bot, message) diff --git a/lib/cmd_embeds.py b/lib/cmd_embeds.py new file mode 100644 index 0000000..842f756 --- /dev/null +++ b/lib/cmd_embeds.py @@ -0,0 +1,65 @@ +from discord import Embed, Color + + +async def help_embed(chnl): + embed = Embed( + title="The OutN Project v8", + url='https://github.com/Pranjal-SB/OutN/', + color=0x6CB5E5, + description='An Amazing FOSS Pokémon assist and more bot for the discord game "Poketwo".\nBelow are its features.', + ) + embed.add_field( + name="Automatic naming", + value="OutN automatically recognises the Pokémon and provides its name in the chat as an embed.", + inline=False, + ) + embed.add_field( + name="Rare Ping", + value="OutN automatically pings the configured role if any mythic, legendary or ultra-beast Pokémon spawns.", + inline=False, + ) + embed.add_field( + name="Regional Ping", + value="OutN automatically pings the configured role if any Regional Pokémon spawns.", + inline=False, + ) + embed.add_field( + name="Automatic starboard", + value="OutN automatically sends any rare Pokémon that spawns in the respective starboard channel.", + inline=False, + ) + embed.add_field( + name="Catch logs", + value="OutN automatically recognises catches and logs them in the respective channel", + inline=False, + ) + embed.add_field( + name="Spawn logs", + value="OutN automatically records all the spawns in the respective channel", + inline=False, + ) + embed.add_field( + name="Hint solving", + value="OutN automatically recognises hints and solves them for you.", + inline=False, + ) + embed.add_field( + name="Manual Identification | identify command", + value="OutN can also manually identify any pokemon and tell you the name.\nJust do 'on.identify' and attach the image to the message", + inline=False, + ) + embed.add_field( + name="Help command", + value="This message.", + inline=False, + ) + embed.set_footer(text="❤️ The OutN Project") + await chnl.send(embed=embed) + +async def identify_embed(message, name): + embed = Embed(color=Color.blue()) + embed.set_footer(text="❤️ The OutN Project") + embed.add_field(name='Pokémon Identified!', + value=f"It's **__{name}__**! catch it using:") + embed.add_field(name='Command', value=f"@Pokétwo#8236 c {name}") + await message.channel.send(embed=embed) diff --git a/lib/makeconfig.py b/lib/config.py similarity index 64% rename from lib/makeconfig.py rename to lib/config.py index 7debb4c..be60014 100644 --- a/lib/makeconfig.py +++ b/lib/config.py @@ -5,6 +5,7 @@ config = configparser.ConfigParser() config_file = 'config.ini' + def get_config(): if not os.path.exists(config_file): token = input("Enter your Discord bot token: ") @@ -36,16 +37,36 @@ def get_config(): config['CONFIRMS'] = { 'RPINGCONFIRM': rpingconfirm, 'REGPINGCONFIRM': regpingconfirm, 'STARCHCONFIRM': starchconfirm, 'CLOGCONFIRM': clogconfirm, 'SPAWNLOGCONFIRM': spawnlogconfirm - } - - config['DEFAULT'] = {'TOKEN': token, 'RPING': rping, 'REGPING': regping, 'STARCH': starch, 'CLOG': clog, 'SPAWNLOG': spawnlog} + } + + config['DEFAULT'] = {'TOKEN': token, 'RPING': rping, 'REGPING': regping, + 'STARCH': starch, 'CLOG': clog, 'SPAWNLOG': spawnlog} with open(config_file, 'w') as configfile: config.write(configfile) else: config.read(config_file) + get_config() +config.read(config_file) + +# variables TKN = config['DEFAULT']['TOKEN'] + +rpingconfirm = config['CONFIRMS']['RPINGCONFIRM'] +regpingconfirm = config['CONFIRMS']['REGPINGCONFIRM'] +starchconfirm = config['CONFIRMS']['STARCHCONFIRM'] +clogconfirm = config['CONFIRMS']['CLOGCONFIRM'] +spawnlogconfirm = config['CONFIRMS']['SPAWNLOGCONFIRM'] + +rping = int(config['DEFAULT']['RPING']) if config['DEFAULT']['RPING'] else None +regping = int(config['DEFAULT']['REGPING'] + ) if config['DEFAULT']['REGPING'] else None +starch = int(config['DEFAULT']['STARCH'] + ) if config['DEFAULT']['STARCH'] else None +clog = int(config['DEFAULT']['CLOG']) if config['DEFAULT']['CLOG'] else None +spawnlog = int(config['DEFAULT']['SPAWNLOG'] + ) if config['DEFAULT']['SPAWNLOG'] else None diff --git a/lib/spawn_embeds.py b/lib/spawn_embeds.py index a9622c9..c6615c2 100644 --- a/lib/spawn_embeds.py +++ b/lib/spawn_embeds.py @@ -1,17 +1,6 @@ from discord import Embed, Color -import configparser - -#config -config = configparser.ConfigParser() -config_file = 'config.ini' -config.read(config_file) - -rping = int(config['DEFAULT']['RPING']) -regping = int(config['DEFAULT']['REGPING']) - -rpingconfirm = config['CONFIRMS']['RPINGCONFIRM'] -regpingconfirm = config['CONFIRMS']['REGPINGCONFIRM'] +from config import rpingconfirm, regpingconfirm, rping, regping #embeds async def mythic_embed(message, name): diff --git a/lib/spawn_logger.py b/lib/spawn_logger.py index 9a93b3d..d3258c3 100644 --- a/lib/spawn_logger.py +++ b/lib/spawn_logger.py @@ -1,13 +1,6 @@ from discord import Color, Embed -import configparser - -# config -config = configparser.ConfigParser() -config_file = 'config.ini' -config.read(config_file) - -spawnlog = int(config['DEFAULT']['SPAWNLOG']) +from config import spawnlog async def logthespawn(bot, message, name): splog = bot.get_channel(spawnlog) diff --git a/lib/star_helper.py b/lib/star_helper.py index 98952b7..0f3e30b 100644 --- a/lib/star_helper.py +++ b/lib/star_helper.py @@ -1,14 +1,6 @@ from discord import Embed, Color -import configparser - - -#config -config = configparser.ConfigParser() -config_file = 'config.ini' -config.read(config_file) - -starch = int(config['DEFAULT']['STARCH']) +from config import starch async def starit_mythic(bot, message, name): starboard = bot.get_channel(starch) diff --git a/main.py b/main.py index 6127157..f436065 100644 --- a/main.py +++ b/main.py @@ -1,27 +1,19 @@ -import configparser import sys - import discord from discord.ext import commands sys.path.append('lib') -from makeconfig import get_config -from TheOutNModule import outnmodule +from config import get_config, TKN, clogconfirm +from TheOutNModule import outnmodule, identifycmd import hint_helper import catch_helper +import cmd_embeds -version = 'v7.1' +version = 'v8' #config get_config() -config = configparser.ConfigParser() -config_file = 'config.ini' -config.read(config_file) - -TKN = config['DEFAULT']['TOKEN'] -clogconfirm = config['CONFIRMS']['CLOGCONFIRM'] - #bot setup intents = discord.Intents.all() intents.message_content = True @@ -64,4 +56,17 @@ async def on_message(message): for i in hint_helper.solve(message.content): await hint_helper.hint_embed(i, message) + elif 'on.' in message.content: + msg = message.content + chnl = message.channel + + if 'help' in msg.lower(): + await cmd_embeds.help_embed(chnl) + + elif 'identify' in msg.lower(): + if message.attachments: + url = message.attachments[0].url + await identifycmd(message, url) + + bot.run(TKN)