From f9f93afcd1d1367563a8028a503fad3803ddb177 Mon Sep 17 00:00:00 2001 From: Giovani Date: Fri, 30 Jul 2021 12:52:10 -0400 Subject: [PATCH] wip: work on new poll command --- cogs/__init__.py | 3 +++ cogs/finance.py | 9 ++++----- cogs/fun.py | 26 +++++++++++++++++++++++++- cogs/{python.py => programming.py} | 6 +++--- data/__init__.py | 1 + pyvis.py | 10 +++++----- 6 files changed, 41 insertions(+), 14 deletions(-) rename cogs/{python.py => programming.py} (57%) create mode 100644 data/__init__.py diff --git a/cogs/__init__.py b/cogs/__init__.py index e69de29..afdabf1 100644 --- a/cogs/__init__.py +++ b/cogs/__init__.py @@ -0,0 +1,3 @@ +from cogs.finance import Finance +from cogs.fun import Fun +from cogs.programming import Programming \ No newline at end of file diff --git a/cogs/finance.py b/cogs/finance.py index fae345a..212ca84 100644 --- a/cogs/finance.py +++ b/cogs/finance.py @@ -1,5 +1,4 @@ import os -from typing import List import requests import json from discord.ext import commands @@ -8,8 +7,8 @@ class Finance(commands.Cog): """Commands to query stock and crypto prices.""" @commands.command(usage="") - async def stock(self, ctx, *tickers: List[str]) -> None: - """Get prices for the given stock tickers. Will default tickers to AAPL, GOOG, MSFT and AMZN if none provided.""" + async def stock(self, ctx, *tickers: str) -> None: + """Gets prices for the given stock tickers. Will default tickers to AAPL, GOOG, MSFT and AMZN if none provided.""" ALPHAVANTAGE_API_KEY = os.getenv('ALPHAVANTAGE_API_KEY') # default tickers @@ -42,8 +41,8 @@ class Finance(commands.Cog): await ctx.send(msg_response) @commands.command(usage="") - async def crypto(self, ctx, *tickers: List[str]) -> None: - """Get prices for the given crypto tickers. Will default tickers to BTC, ETH and LTC if none provided.""" + async def crypto(self, ctx, *tickers: str) -> None: + """Gets prices for the given crypto tickers. Will default tickers to BTC, ETH and LTC if none provided.""" LUNAR_CRUSH_API_KEY = os.getenv("LUNAR_CRUSH_API_KEY") # default tickers diff --git a/cogs/fun.py b/cogs/fun.py index 2c4f837..73a0793 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -3,8 +3,11 @@ import discord import requests import json import requests +from datetime import date from discord.ext import commands +OPTION_EMOJIS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"] + class Fun(commands.Cog): """Commands that are good for the soul!""" @@ -41,4 +44,25 @@ class Fun(commands.Cog): github_embed.add_field(name="Open Issues", value=repo_info['open_issues'], inline=True) github_embed.set_footer(text=f"Repo created at • {repo_info['created_at'].split('T')[0]}") - await ctx.send(embed=github_embed) \ No newline at end of file + await ctx.send(embed=github_embed) + + @commands.command(usage="\"\" ") + async def poll(self, ctx, *params: str) -> None: + """Creates a poll with the given parameters.""" + + if len(params) <= 1: + await ctx.send("**Please provide the parameters for the poll. ex.** `!poll \"My question?\" option1 option2`") + return + + question = params[0] + options = params[1:] + + # create embed response + poll_embed = discord.Embed(title=question, description="\u200b", color=0x3DCCDD) + for i in range(len(options)): + poll_embed.add_field(value="\u200b", name=f"{OPTION_EMOJIS[i]} {options[i]}", inline=False) + poll_embed.set_footer(text=f"Poll created on • {date.today().strftime('%m/%d/%y')}") + + message = await ctx.send(embed=poll_embed) + for i in range(len(options)): + await message.add_reaction(OPTION_EMOJIS[i]) \ No newline at end of file diff --git a/cogs/python.py b/cogs/programming.py similarity index 57% rename from cogs/python.py rename to cogs/programming.py index fd7ea42..9fc03fc 100644 --- a/cogs/python.py +++ b/cogs/programming.py @@ -1,9 +1,9 @@ from discord.ext import commands -class Python(commands.Cog): - """Commands about python programming.""" +class Programming(commands.Cog): + """Commands about programming.""" @commands.command() async def resources(self, ctx) -> None: - """Will provide resources for python programming.""" + """Will provide resources for programming.""" await ctx.send("Some resources for you here!") # TODO: Add resources \ No newline at end of file diff --git a/data/__init__.py b/data/__init__.py new file mode 100644 index 0000000..f0be901 --- /dev/null +++ b/data/__init__.py @@ -0,0 +1 @@ +DUMMY_CACHE = {} \ No newline at end of file diff --git a/pyvis.py b/pyvis.py index c0f0917..ccdebc1 100644 --- a/pyvis.py +++ b/pyvis.py @@ -3,9 +3,9 @@ import os import requests import json import random -from cogs.python import Python -from cogs.fun import Fun -from cogs.finance import Finance +from cogs import Programming +from cogs import Fun +from cogs import Finance from discord.ext import commands from dotenv import load_dotenv from pretty_help import DefaultMenu, PrettyHelp @@ -34,7 +34,7 @@ async def on_ready(): @bot.event async def on_member_join(member): guild = discord.utils.find(lambda g: g.name == DISCORD_GUILD_NAME, bot.guilds) # TODO: check if find will throw an error - welcome_channel = discord.utils.find(lambda c: c.name == "👋welcome", guild.channels) # TODO: remove welcome channel hardcod + welcome_channel = discord.utils.find(lambda c: c.name == "👋welcome", guild.channels) # TODO: remove welcome channel hardcode http_response = requests.get(f"https://api.giphy.com/v1/gifs/search?api_key={GIPHY_API_KEY}&q=welcome&limit=25&offset=0&rating=pg-13&lang=en") welcome_gifs = json.loads(http_response.text) @@ -64,7 +64,7 @@ menu = DefaultMenu('◀️', '▶️', '❌') bot.help_command = PrettyHelp(navigation=menu, color=discord.Colour.green()) # commands by category a.k.a. cogs -bot.add_cog(Python()) +bot.add_cog(Programming()) bot.add_cog(Fun()) bot.add_cog(Finance())