-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 20 #6
base: master
Are you sure you want to change the base?
Team 20 #6
Changes from 15 commits
04aef2f
b6cb07d
fc72a23
11dd8f0
47f3884
d5b9611
f507dd4
c3c654c
7c150e4
c311b1d
ba5580a
5b686ee
d8fed73
48e2a64
ca8787b
0b50a56
23ce5a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| # coding=utf-8 | ||
| import asyncio | ||
| import json | ||
| import logging | ||
| from typing import Any, Dict | ||
| import random | ||
| from typing import Tuple | ||
|
|
||
| from discord import Embed, FFmpegPCMAudio | ||
| from discord.ext.commands import AutoShardedBot, Context, command | ||
| from discord.opus import is_loaded, load_opus | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -14,8 +19,14 @@ class Snakes: | |
|
|
||
| def __init__(self, bot: AutoShardedBot): | ||
| self.bot = bot | ||
| self.python_image = "https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" | ||
| self.python_info = ("The Python Programming language(Python Sermone) is a dynamically typed, interpreted " | ||
| "programming language. It is a member of the high level programming languges usually " | ||
| "found in areas like backend web development data science and AI.") | ||
| with open("bot/db/db.json", "r") as db: | ||
| self.db = json.load(db) | ||
|
|
||
| async def get_snek(self, name: str = None) -> Dict[str, Any]: | ||
| async def get_snek(self, name: str = None) -> Tuple[str, str, str]: | ||
| """ | ||
| Go online and fetch information about a snake | ||
|
|
||
|
|
@@ -28,6 +39,17 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: | |
| :param name: Optional, the name of the snake to get information for - omit for a random snake | ||
| :return: A dict containing information on a snake | ||
| """ | ||
| if name: | ||
| name = name.lower() | ||
| if name == "python": | ||
| return ("python", self.python_info, self.python_image) | ||
| else: | ||
| for key in self.db.keys(): | ||
| if key.lower() == name.lower(): | ||
| return (key, self.db[key][0], self.db[key][1]) | ||
| else: | ||
| key = random.choice(list(self.db.keys())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the key = random.choice(list(self.db)) |
||
| return (key, self.db[key][0], self.db[key][1]) | ||
|
|
||
| @command() | ||
| async def get(self, ctx: Context, name: str = None): | ||
|
|
@@ -40,10 +62,33 @@ async def get(self, ctx: Context, name: str = None): | |
| :param ctx: Context object passed from discord.py | ||
| :param name: Optional, the name of the snake to get information for - omit for a random snake | ||
| """ | ||
| snake = await self.get_snek(name) | ||
| if snake: | ||
| snake_embed = Embed(title=snake[0], description=snake[1]) | ||
| snake_embed.set_image(url=snake[2]) | ||
| await ctx.send(embed=snake_embed) | ||
| else: | ||
| await ctx.send("I was not able to find your snake, I am sorry.") | ||
|
|
||
| # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
| @command() | ||
| async def hiss(self, ctx: Context): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone executes this twice within a short period of time will there be an error, or will the sound play twice at the same time?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to check the clients voice status before making it play more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discordpy appears to handle this fine.(just tested it) |
||
| """ | ||
| Hisssses in a voice channel | ||
| """ | ||
| voice_channel = ctx.message.author.voice.channel | ||
| if voice_channel: | ||
| voice_client = await voice_channel.connect() | ||
| hiss = FFmpegPCMAudio("bot/db/sound1.mp3") | ||
|
|
||
| def disconnect(errors): | ||
| disconnect_coro = voice_client.disconnect() | ||
| asyncio.run_coroutine_threadsafe(disconnect_coro, self.bot.loop) | ||
| voice_client.play(hiss, after=disconnect) | ||
|
|
||
|
|
||
| def setup(bot): | ||
| if not is_loaded(): | ||
| load_opus() | ||
| bot.add_cog(Snakes(bot)) | ||
| log.info("Cog loaded: Snakes") | ||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you already lowered the name..?