From 215869f6d3c43ba7ebffb4735a9dfaaa69358adc Mon Sep 17 00:00:00 2001 From: redcreeper14385 Date: Tue, 31 Aug 2021 17:35:22 +0100 Subject: Improve the drama command, and fix a broken source --- cogs/fun.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cogs/fun.py b/cogs/fun.py index 3ce1ed1..c105934 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -2,6 +2,7 @@ import discord import requests from discord.ext import commands import urllib.request +import random class Fun(commands.Cog): def __init__(self, bot): @@ -10,25 +11,23 @@ class Fun(commands.Cog): @commands.command(name="drama", brief="Wait, it's all discord-meta? Always has been.", help=""" Fetches drama from various sources, all based on asiekierka's original generator. Valid sources: - `ftb`: `fabric`: `forge`: + If no source (or an invalid source) is provided then a random one is picked from between the two. """) - async def drama(self, ctx, source): + async def drama(self, ctx, source=None): + url = "" if source == "fabric": - response = urllib.request.urlopen("https://fabric-drama.herokuapp.com/txt").read().decode('utf-8') - await ctx.send(response) - elif source == "ftb": - try: - response = urllib.request.urlopen("http://ftb-drama.herokuapp.com/txt").read().decode('utf-8') - await ctx.send(response) - except HTTPError: - await ctx.send("This site is currently unavailable.") + url = "https://fabric-drama.herokuapp.com/txt" elif source == "forge": - response = urllib.request.urlopen("https://mc-drama.herokuapp.com/raw").read().decode('utf-8') - await ctx.send(response) + url = "https://mc-drama.herokuapp.com/raw" else: - await ctx.send(f'Could not find drama from source "{source}". Valid sources: `ftb`, `fabric`, `forge`.') + url = random.choice(["https://fabric-drama.herokuapp.com/txt", "https://mc-drama.herokuapp.com/raw"]) + response = urllib.request.urlopen(url).read().decode('utf-8') + embed = discord.Embed(color=0xa37dca) + embed.add_field(name=f"{ctx.author.name} caused drama!", value=response, inline=False) + embed.set_footer(text="Tiny Potato Bot v1.0.0") + await ctx.send(embed=embed) @commands.command(name="mixinerror", brief="helpful Mixin errors when?", help="helpful Mixin errors when?") async def mixinerror(self, ctx): -- cgit 1.4.1-2-gfad0 > ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15