Skip to content

Commit

Permalink
OutN Upgrade -> v8
Browse files Browse the repository at this point in the history
## v8
-added commands!!!
    - added help command
    - added identify command
  • Loading branch information
Pranjal-SB committed Jun 26, 2024
1 parent bf49f1c commit 09048b3
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@
## v7.1
- optimized code
- removed useless files and parts

## v8
-added commands!!!
- added help command
- added identify command
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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".

Expand Down Expand Up @@ -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
Expand All @@ -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..


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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!
Expand Down
25 changes: 16 additions & 9 deletions lib/TheOutNModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

9 changes: 1 addition & 8 deletions lib/catch_helper.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
65 changes: 65 additions & 0 deletions lib/cmd_embeds.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 24 additions & 3 deletions lib/makeconfig.py → lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down Expand Up @@ -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
13 changes: 1 addition & 12 deletions lib/spawn_embeds.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
9 changes: 1 addition & 8 deletions lib/spawn_logger.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 1 addition & 9 deletions lib/star_helper.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
29 changes: 17 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 09048b3

Please sign in to comment.