Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Discord (you)
MASTER_ID=null # [0-9]

# Discord (bot)
CLIENT_ID=null # [0-9]
CLIENT_SECRET=null # [0-9a-zA-Z]
TOKEN=null # [0-9a-zA-Z\.]

# Imgur
imgur_client_id=null # [0-9a-z]
imgur_client_secret=null # [0-9a-z]

# Config
BOT_PREFIX=;
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ IO\ Files/*
__pycache__
*.lnk
*.cmd
var_secrets.py
venv/*
venv/
.env.local
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"mikestead.dotenv",
"ms-python.python"
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.formatting.provider": "black",
"editor.tabSize": 4
}
293 changes: 135 additions & 158 deletions PokeCord.py

Large diffs are not rendered by default.

35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,50 @@ Is a bot where every so often a pokemon spawns and has to be guessed to be caugh

### Installing

Create your API secrets and input them into the '[var_secrets.py](var_secrets.py)' file, with the values enclosed in quotes.
1. Create virtual environment `py -m venv venv && venv/Scripts/activate`

2. Install dependencies: `pip install -r requirements.txt`

3. Create a copy of `.env` and name it `.env.local`

4. Create your API secrets and put them in `.env.local`

- [imgur](https://api.imgur.com/oauth2/addclient)
- Application name: `PokeCord` (can be whatever you want)
- Authorization type: `OAuth 2 authorization with a callback URL`
- Authorization callback URL: `https://imgur.com`
- On submit, edit `imgr_client_id` and `imgr_client_secret`
- [discord](https://discordpy.readthedocs.io/en/latest/discord.html)

To install the dependencies for the project run `pip install -r requirements.txt`.
Example `.env.local`:

* **Note: the bot will still have to be added to the discord channel**
> MASTER_ID = "abcd#1234"
>
> CLIENT_ID = abcd1234
> ...

- **Note: the bot will still have to be added to the discord channel**

### Running

Run '[runbot.bat](runbot.bat)' after installing to start the bot.

- If you're using virtualenv: `py main.py`

## Built with

* Windows 10 (Untested on Linux)
* [discord.ext](https://discordpy.readthedocs.io/en/latest/ext/commands/index.html) - Interactions with Discord
* [Pillow](https://pillow.readthedocs.io/en/stable/reference/Image.html) - Image Editing
* [imgurpython](https://github.com/Imgur/imgurpython) - Image Uploading
- Windows 10 (Untested on Linux)
- [discord.ext](https://discordpy.readthedocs.io/en/latest/ext/commands/index.html) - Interactions with Discord
- [Pillow](https://pillow.readthedocs.io/en/stable/reference/Image.html) - Image Editing
- [imgurpython](https://github.com/Imgur/imgurpython) - Image Uploading

## To-do

- [x] Catch-able Pokemon
- [ ] Admin Change spawn time
- [ ] Limit which region is spawned
- [ ] Fix checking and catching channel
- [ ] Fix Re-coloring
- [ ] Add items
- [ ] Add leveling and battling
- [ ] Add variabled spawn rate based off rarity (maybe)
- [ ] Add variabled spawn rate based off rarity (maybe)
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from var_secrets import imgur_client_id, imgur_client_secret
import env

import os
import json
Expand All @@ -11,7 +11,7 @@
# DISCORD VARS #
#client = discord.Client()

BOT_PREFIX = ";"
BOT_PREFIX = env.get("BOT_PREFIX")
CHANNEL_IDs = ("449281327988998156")

# PYTHON VALS #
Expand All @@ -27,7 +27,7 @@ class bcolors:

# Globals #

imgur_client = ImgurClient(imgur_client_id, imgur_client_secret)
imgur_client = ImgurClient(env.get("imgur_client_id"), env.get("imgur_client_secret"))

# Image Vars #
white = (255,255,255)
Expand Down
11 changes: 11 additions & 0 deletions env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
from dotenv import dotenv_values

var = {
**dotenv_values(".env"),
**dotenv_values(".env.local"),
**os.environ
}

def get(key):
return var[key]
50 changes: 50 additions & 0 deletions log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from datetime import datetime
from enum import Enum


class LEVEL(Enum):
INFO = 1
ERROR = 2
WARN = 3
DEBUG = 4

def __ge__(self, other):
if self.__class__ is other.__class__:
return self.value >= other.value
return NotImplemented

def __gt__(self, other):
if self.__class__ is other.__class__:
return self.value > other.value
return NotImplemented

def __le__(self, other):
if self.__class__ is other.__class__:
return self.value <= other.value
return NotImplemented

def __lt__(self, other):
if self.__class__ is other.__class__:
return self.value < other.value
return NotImplemented


level = LEVEL.DEBUG


def separator():
print("~~~~~~~~~~~~")


def info(*args, **kwargs):
if level >= LEVEL.INFO:
print(f"[{datetime.now().strftime('%b-%d %H:%M')} INFO]", *args, **kwargs)


def debug(*args, **kwargs):
if level >= LEVEL.DEBUG:
print(f"[DEBUG]", *args, **kwargs)


# def error()
# def warn()
19 changes: 6 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import sys
import env, log, sys, config, pickle
from pathlib import Path
import config
from var_secrets import TOKEN
from PokeCord import *

import pickle

from datetime import timedelta, datetime

# Checking folders exist
if not os.path.isdir("IO Files/"):
print("Creating IO Files folder...")
Expand All @@ -25,8 +19,8 @@

@bot.event
async def on_connect():
print('~~~~~~~~~~~~')
print(f"[{datetime.now().strftime('%b-%d %H:%M')}] Logged in as {bot.user.name}(ID: {bot.user.id})")
log.separator()
log.info(f"Logged in as {bot.user.name}(ID: {bot.user.id})")
if os.path.isfile("IO Files/PokeCord.pickle"):
with open("IO Files/PokeCord.pickle", 'rb') as file:
try:
Expand All @@ -48,7 +42,7 @@ async def on_connect():

@bot.event
async def on_command(context):
print(f"[{datetime.now().strftime('%b-%d %H:%M')}]: '{context.command}' by {context.author}")
log.info(f"'{context.command}' by {context.author}")
pass

@bot.event
Expand All @@ -75,6 +69,5 @@ async def cmd_restart(ctx):
async def cmd_shutdown(context):
await bot.close()


print(f"[{datetime.now().strftime('%b-%d %H:%M')}] Start Bot")
bot.run(TOKEN)
log.info("Start Bot")
bot.run(env.get("TOKEN"))
Loading