wip: work on new poll command

This commit is contained in:
2021-07-30 12:52:10 -04:00
parent 83672bba00
commit f9f93afcd1
6 changed files with 41 additions and 14 deletions

View File

@@ -0,0 +1,3 @@
from cogs.finance import Finance
from cogs.fun import Fun
from cogs.programming import Programming

View File

@@ -1,5 +1,4 @@
import os import os
from typing import List
import requests import requests
import json import json
from discord.ext import commands from discord.ext import commands
@@ -8,8 +7,8 @@ class Finance(commands.Cog):
"""Commands to query stock and crypto prices.""" """Commands to query stock and crypto prices."""
@commands.command(usage="<tickers>") @commands.command(usage="<tickers>")
async def stock(self, ctx, *tickers: List[str]) -> None: async def stock(self, ctx, *tickers: str) -> None:
"""Get prices for the given stock tickers. Will default tickers to AAPL, GOOG, MSFT and AMZN if none provided.""" """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') ALPHAVANTAGE_API_KEY = os.getenv('ALPHAVANTAGE_API_KEY')
# default tickers # default tickers
@@ -42,8 +41,8 @@ class Finance(commands.Cog):
await ctx.send(msg_response) await ctx.send(msg_response)
@commands.command(usage="<tickers>") @commands.command(usage="<tickers>")
async def crypto(self, ctx, *tickers: List[str]) -> None: async def crypto(self, ctx, *tickers: str) -> None:
"""Get prices for the given crypto tickers. Will default tickers to BTC, ETH and LTC if none provided.""" """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") LUNAR_CRUSH_API_KEY = os.getenv("LUNAR_CRUSH_API_KEY")
# default tickers # default tickers

View File

@@ -3,8 +3,11 @@ import discord
import requests import requests
import json import json
import requests import requests
from datetime import date
from discord.ext import commands from discord.ext import commands
OPTION_EMOJIS = ["1", "2", "3", "4", "5"]
class Fun(commands.Cog): class Fun(commands.Cog):
"""Commands that are good for the soul!""" """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.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]}") github_embed.set_footer(text=f"Repo created at • {repo_info['created_at'].split('T')[0]}")
await ctx.send(embed=github_embed) await ctx.send(embed=github_embed)
@commands.command(usage="\"<question>\" <options>")
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])

View File

@@ -1,9 +1,9 @@
from discord.ext import commands from discord.ext import commands
class Python(commands.Cog): class Programming(commands.Cog):
"""Commands about python programming.""" """Commands about programming."""
@commands.command() @commands.command()
async def resources(self, ctx) -> None: 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 await ctx.send("Some resources for you here!") # TODO: Add resources

1
data/__init__.py Normal file
View File

@@ -0,0 +1 @@
DUMMY_CACHE = {}

View File

@@ -3,9 +3,9 @@ import os
import requests import requests
import json import json
import random import random
from cogs.python import Python from cogs import Programming
from cogs.fun import Fun from cogs import Fun
from cogs.finance import Finance from cogs import Finance
from discord.ext import commands from discord.ext import commands
from dotenv import load_dotenv from dotenv import load_dotenv
from pretty_help import DefaultMenu, PrettyHelp from pretty_help import DefaultMenu, PrettyHelp
@@ -34,7 +34,7 @@ async def on_ready():
@bot.event @bot.event
async def on_member_join(member): 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 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") 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) welcome_gifs = json.loads(http_response.text)
@@ -64,7 +64,7 @@ menu = DefaultMenu('◀️', '▶️', '❌')
bot.help_command = PrettyHelp(navigation=menu, color=discord.Colour.green()) bot.help_command = PrettyHelp(navigation=menu, color=discord.Colour.green())
# commands by category a.k.a. cogs # commands by category a.k.a. cogs
bot.add_cog(Python()) bot.add_cog(Programming())
bot.add_cog(Fun()) bot.add_cog(Fun())
bot.add_cog(Finance()) bot.add_cog(Finance())