Skip to content

Commit

Permalink
Snake cog (#78)
Browse files Browse the repository at this point in the history
* Added the random_snake_name feature, created by Iceman

* Added Antidote to the snake_cog.

* Add the snake quiz from Team 7 - Mushy and Cardium - to the snakes cog. (#74)

Original PR: python-discord/code-jam-1#2
Completes task: https://app.clickup.com/754996/757069/t/2ww7u

* Cleaned up the snake quiz

* Cleaning up snake_quiz further and integrating it towards the new API for snake questions.

* Bugfixes for Antidote and Quiz

* Implemented the zzzen of pythhhon, by prithaj and andrew.

* Added the snake facts feature by Andrew and Prithaj. Also cleaned up some code smell.

* Implemented the snake_videos feature. Also made a fix for a bug with https sessions on local aiohttp

* Implemented Momo and kel's snake perlin noise gen draw feature

* Implemented the hatch feature from Momo and Kels PR

* Implemented the snakemefeature from the momo and kel PR, with big modifications. It no longer uses markov, it was just too slow to get it to do something interesting. It can also be passed a message to snakify that instead.

* Started on Snakes and Ladders, but want to refactor it to use reactions. Fixed up the perlin noise gen to generate random snake attributes.

* Movie command, initial version

* Snakes and Ladders implemented and rewritten to use reactions for controls.

* made the snek draw feature even more fabulous.

* SAL, get_snek, perlin

* Fixing some minor problems with startup log spam. The bot will now only try to post to DEVLOG if it's not in debug mode. Also added the new snake API endpoints and prepping for database handling of all snek related datapoints.

* Pointed all relevant functions at their respective snake API endpoints. Tested. All the data is now in our database, and everything appears to work.

* Added the guessing game by Ava and eivl

* Trailing comma, baby

* Added snake cards.

* Added the snakes.about command, and cleaned up the cog. Still got a couple of bugs with snake_card, but other than that this is done.

* Some fixes for the snake cards. Cards now use the converter on the snake input, so it can disambiguate just like .get. Also made the special cases like bob ross available to both .get and .card

* Some fixes to address Volcyy's review.

* Addressing comments by gdude on the site PR

* Changes requested by Joseph
  • Loading branch information
lemonsaurus authored and jb3 committed May 19, 2018
1 parent b96f02a commit ebf3b9e
Show file tree
Hide file tree
Showing 28 changed files with 2,271 additions and 81 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ logmatic-python = "*"
aiohttp = "<2.3.0,>=2.0.0"
websockets = ">=4.0,<5.0"
yarl = "==1.1.1"
fuzzywuzzy = "*"
python-levenshtein = "*"

[dev-packages]
"flake8" = "*"
Expand Down
23 changes: 19 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def parse_python(buffer_pos):

# Args handling
new_args = []

if args:
# Force args into container
if not isinstance(args, tuple):
Expand Down Expand Up @@ -227,6 +228,7 @@ def parse_python(buffer_pos):

# Iterate through the buffer and determine
pos = 0
current = None
while not self.eof:
try:
current = self.buffer[self.index + pos]
Expand Down
1 change: 1 addition & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
bot.load_extension("bot.cogs.eval")
bot.load_extension("bot.cogs.fun")
bot.load_extension("bot.cogs.hiphopify")
bot.load_extension("bot.cogs.snakes")
bot.load_extension("bot.cogs.tags")
bot.load_extension("bot.cogs.verification")

Expand Down
22 changes: 14 additions & 8 deletions bot/cogs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
NoPrivateMessage, UserInputError
)

from bot.constants import DEVLOG_CHANNEL, PYTHON_GUILD, SITE_API_KEY, SITE_API_USER_URL
from bot.constants import (
DEBUG_MODE, DEVLOG_CHANNEL, PYTHON_GUILD,
SITE_API_KEY, SITE_API_URL
)

log = logging.getLogger(__name__)
USERS_URL = f"{SITE_API_URL}/bot/users"


class Events:
Expand All @@ -24,13 +28,13 @@ async def send_updated_users(self, *users, replace_all=False):
try:
if replace_all:
response = await self.bot.http_session.post(
url=SITE_API_USER_URL,
url=USERS_URL,
json=list(users),
headers={"X-API-Key": SITE_API_KEY}
)
else:
response = await self.bot.http_session.put(
url=SITE_API_USER_URL,
url=USERS_URL,
json=list(users),
headers={"X-API-Key": SITE_API_KEY}
)
Expand All @@ -43,7 +47,8 @@ async def send_updated_users(self, *users, replace_all=False):
async def send_delete_users(self, *users):
try:
response = await self.bot.http_session.delete(
url=SITE_API_USER_URL,
url=USERS_URL,

json=list(users),
headers={"X-API-Key": SITE_API_KEY}
)
Expand Down Expand Up @@ -88,7 +93,7 @@ async def on_command_error(self, ctx: Context, e: CommandError):
f"Sorry, an unexpected error occurred. Please let us know!\n\n```{e}```"
)
raise e.original
log.error(f"COMMAND ERROR: '{e}'")
raise e

async def on_ready(self):
users = []
Expand Down Expand Up @@ -124,9 +129,10 @@ async def on_ready(self):
name=key, value=str(value)
)

await self.bot.get_channel(DEVLOG_CHANNEL).send(
embed=embed
)
if not DEBUG_MODE:
await self.bot.get_channel(DEVLOG_CHANNEL).send(
embed=embed
)

async def on_member_update(self, before: Member, after: Member):
if before.roles == after.roles and before.name == after.name and before.discriminator == after.discriminator:
Expand Down
9 changes: 5 additions & 4 deletions bot/cogs/hiphopify.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from bot.constants import (
ADMIN_ROLE, MODERATOR_ROLE, MOD_LOG_CHANNEL,
NEGATIVE_REPLIES, OWNER_ROLE, POSITIVE_REPLIES,
SITE_API_HIPHOPIFY_URL, SITE_API_KEY
SITE_API_KEY, SITE_API_URL
)
from bot.decorators import with_role

Expand All @@ -23,6 +23,7 @@ class Hiphopify:
def __init__(self, bot: AutoShardedBot):
self.bot = bot
self.headers = {"X-API-KEY": SITE_API_KEY}
self.url = f"{SITE_API_URL}/bot/hiphopify"

async def on_member_update(self, before, after):
"""
Expand All @@ -42,7 +43,7 @@ async def on_member_update(self, before, after):
)

response = await self.bot.http_session.get(
SITE_API_HIPHOPIFY_URL,
self.url,
headers=self.headers,
params={"user_id": str(before.id)}
)
Expand Down Expand Up @@ -104,7 +105,7 @@ async def hiphopify(self, ctx: Context, member: Member, duration: str, forced_ni
params["forced_nick"] = forced_nick

response = await self.bot.http_session.post(
SITE_API_HIPHOPIFY_URL,
self.url,
headers=self.headers,
json=params
)
Expand Down Expand Up @@ -167,7 +168,7 @@ async def unhiphopify(self, ctx: Context, member: Member):
embed.colour = Colour.blurple()

response = await self.bot.http_session.delete(
SITE_API_HIPHOPIFY_URL,
self.url,
headers=self.headers,
json={"user_id": str(member.id)}
)
Expand Down
5 changes: 3 additions & 2 deletions bot/cogs/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from discord import Embed
from discord.ext.commands import AutoShardedBot

from bot.constants import DEVLOG_CHANNEL
from bot.constants import DEBUG_MODE, DEVLOG_CHANNEL

log = logging.getLogger(__name__)

Expand All @@ -26,7 +26,8 @@ async def on_ready(self):
icon_url="https://raw.githubusercontent.com/discord-python/branding/master/logos/logo_circle.png"
)

await self.bot.get_channel(DEVLOG_CHANNEL).send(embed=embed)
if not DEBUG_MODE:
await self.bot.get_channel(DEVLOG_CHANNEL).send(embed=embed)


def setup(bot):
Expand Down
Loading

0 comments on commit ebf3b9e

Please sign in to comment.