diff --git a/.gitignore b/.gitignore index 46c05fd..8d7de94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ __pycache__/ config.py +venv/ diff --git a/assets/pfp/discord/0e291f67c9274a1abdddeb3fd919cbaa.png b/assets/pfp/discord/0e291f67c9274a1abdddeb3fd919cbaa.png new file mode 100644 index 0000000..da673d8 Binary files /dev/null and b/assets/pfp/discord/0e291f67c9274a1abdddeb3fd919cbaa.png differ diff --git a/assets/pfp/discord/1cbd08c76f8af6dddce02c5138971129.png b/assets/pfp/discord/1cbd08c76f8af6dddce02c5138971129.png new file mode 100644 index 0000000..c2fcb5d Binary files /dev/null and b/assets/pfp/discord/1cbd08c76f8af6dddce02c5138971129.png differ diff --git a/assets/pfp/discord/322c936a8c8be1b803cd94861bdfa868.png b/assets/pfp/discord/322c936a8c8be1b803cd94861bdfa868.png new file mode 100644 index 0000000..3bde60d Binary files /dev/null and b/assets/pfp/discord/322c936a8c8be1b803cd94861bdfa868.png differ diff --git a/assets/pfp/discord/6debd47ed13483642cf09e832ed0bc1b.png b/assets/pfp/discord/6debd47ed13483642cf09e832ed0bc1b.png new file mode 100644 index 0000000..b6295ad Binary files /dev/null and b/assets/pfp/discord/6debd47ed13483642cf09e832ed0bc1b.png differ diff --git a/assets/pfp/discord/dd4dbc0016779df1378e7812eabaa04d.png b/assets/pfp/discord/dd4dbc0016779df1378e7812eabaa04d.png new file mode 100644 index 0000000..ee68ee7 Binary files /dev/null and b/assets/pfp/discord/dd4dbc0016779df1378e7812eabaa04d.png differ diff --git a/assets/pfp/hg/cato.png b/assets/pfp/hg/cato.png new file mode 100644 index 0000000..b43a8eb Binary files /dev/null and b/assets/pfp/hg/cato.png differ diff --git a/assets/pfp/hg/clove.png b/assets/pfp/hg/clove.png new file mode 100644 index 0000000..1f43ea6 Binary files /dev/null and b/assets/pfp/hg/clove.png differ diff --git a/assets/pfp/hg/district10female.png b/assets/pfp/hg/district10female.png new file mode 100644 index 0000000..f088e8d Binary files /dev/null and b/assets/pfp/hg/district10female.png differ diff --git a/assets/pfp/hg/district10male.png b/assets/pfp/hg/district10male.png new file mode 100644 index 0000000..b17fc8e Binary files /dev/null and b/assets/pfp/hg/district10male.png differ diff --git a/assets/pfp/hg/district3female.png b/assets/pfp/hg/district3female.png new file mode 100644 index 0000000..825e1b0 Binary files /dev/null and b/assets/pfp/hg/district3female.png differ diff --git a/assets/pfp/hg/district3male.png b/assets/pfp/hg/district3male.png new file mode 100644 index 0000000..8113aa8 Binary files /dev/null and b/assets/pfp/hg/district3male.png differ diff --git a/assets/pfp/hg/district4female.png b/assets/pfp/hg/district4female.png new file mode 100644 index 0000000..0a26473 Binary files /dev/null and b/assets/pfp/hg/district4female.png differ diff --git a/assets/pfp/hg/district4male.png b/assets/pfp/hg/district4male.png new file mode 100644 index 0000000..019fd75 Binary files /dev/null and b/assets/pfp/hg/district4male.png differ diff --git a/assets/pfp/hg/district5male.png b/assets/pfp/hg/district5male.png new file mode 100644 index 0000000..1b15916 Binary files /dev/null and b/assets/pfp/hg/district5male.png differ diff --git a/assets/pfp/hg/district6female.png b/assets/pfp/hg/district6female.png new file mode 100644 index 0000000..ac04fa6 Binary files /dev/null and b/assets/pfp/hg/district6female.png differ diff --git a/assets/pfp/hg/district7female.png b/assets/pfp/hg/district7female.png new file mode 100644 index 0000000..b29ef52 Binary files /dev/null and b/assets/pfp/hg/district7female.png differ diff --git a/assets/pfp/hg/district7male.png b/assets/pfp/hg/district7male.png new file mode 100644 index 0000000..683f163 Binary files /dev/null and b/assets/pfp/hg/district7male.png differ diff --git a/assets/pfp/hg/district8female.png b/assets/pfp/hg/district8female.png new file mode 100644 index 0000000..3eeadec Binary files /dev/null and b/assets/pfp/hg/district8female.png differ diff --git a/assets/pfp/hg/district8male.png b/assets/pfp/hg/district8male.png new file mode 100644 index 0000000..958d363 Binary files /dev/null and b/assets/pfp/hg/district8male.png differ diff --git a/assets/pfp/hg/district9female.png b/assets/pfp/hg/district9female.png new file mode 100644 index 0000000..79c2e81 Binary files /dev/null and b/assets/pfp/hg/district9female.png differ diff --git a/assets/pfp/hg/district9male.png b/assets/pfp/hg/district9male.png new file mode 100644 index 0000000..a8008d7 Binary files /dev/null and b/assets/pfp/hg/district9male.png differ diff --git a/assets/pfp/hg/foxface.png b/assets/pfp/hg/foxface.png new file mode 100644 index 0000000..9ddab42 Binary files /dev/null and b/assets/pfp/hg/foxface.png differ diff --git a/assets/pfp/hg/glimmer.png b/assets/pfp/hg/glimmer.png new file mode 100644 index 0000000..5f36947 Binary files /dev/null and b/assets/pfp/hg/glimmer.png differ diff --git a/assets/pfp/hg/jason.png b/assets/pfp/hg/jason.png new file mode 100644 index 0000000..43938a3 Binary files /dev/null and b/assets/pfp/hg/jason.png differ diff --git a/assets/pfp/hg/katniss.png b/assets/pfp/hg/katniss.png new file mode 100644 index 0000000..36087da Binary files /dev/null and b/assets/pfp/hg/katniss.png differ diff --git a/assets/pfp/hg/marvel.png b/assets/pfp/hg/marvel.png new file mode 100644 index 0000000..42f14d6 Binary files /dev/null and b/assets/pfp/hg/marvel.png differ diff --git a/assets/pfp/hg/peeta.png b/assets/pfp/hg/peeta.png new file mode 100644 index 0000000..c5fcee6 Binary files /dev/null and b/assets/pfp/hg/peeta.png differ diff --git a/assets/pfp/hg/rue.png b/assets/pfp/hg/rue.png new file mode 100644 index 0000000..4e1d0f9 Binary files /dev/null and b/assets/pfp/hg/rue.png differ diff --git a/assets/pfp/hg/thresh.png b/assets/pfp/hg/thresh.png new file mode 100644 index 0000000..b7bbef5 Binary files /dev/null and b/assets/pfp/hg/thresh.png differ diff --git a/game.py b/game.py index 1f35127..ad97218 100644 --- a/game.py +++ b/game.py @@ -10,6 +10,7 @@ def __init__(self, owner_name, owner_id, title: str): self.owner_id = owner_id self.title = title self.has_started = False + self.is_autostepping = False # Player data self.players = {} @@ -30,9 +31,7 @@ def __init__(self, owner_name, owner_id, title: str): @property def players_sorted(self): - l = list(self.players.values()) - l.sort() - return l + return sorted(list(self.players.values())) def add_player(self, new_player): if new_player.name in self.players: diff --git a/hungrybot.py b/hungrybot.py index bfd5da6..a269452 100644 --- a/hungrybot.py +++ b/hungrybot.py @@ -1,6 +1,9 @@ import discord import re from discord.ext import commands +import pytimeparse +import datetime +import asyncio from default_players import default_players from hungergames import HungerGames @@ -141,7 +144,7 @@ async def status(ctx): @bot.command() @commands.guild_only() -async def start(ctx): +async def start(ctx, auto=None): """ Starts the pending game in the channel. """ @@ -180,6 +183,57 @@ async def step(ctx): await ctx.send(embed=embed) +@bot.command() +@commands.guild_only() +async def autostep(ctx, step_time): + # TODO: Fix this boilerplate spaghetti and fold it into the current error system + if step_time is None: + await ctx.reply("Time interval not specified.") + return + interval = pytimeparse.parse(step_time) + if interval is None: + await ctx.reply("Invalid time interval.") + return + if ctx.channel.id not in hg.active_games: + __check_errors(ctx, ErrorCode.NO_GAME) + if hg.active_games[ctx.channel.id].owner_id is not ctx.author.id: + __check_errors(ctx, ErrorCode.NOT_OWNER) + if not hg.active_games[ctx.channel.id].has_started: + __check_errors(ctx, ErrorCode.GAME_NOT_STARTED) + if hg.active_games[ctx.channel.id].is_autostepping: + await ctx.reply("This game is already autostepping.") + return + interval = max(min(interval, 86400), 5) + hg.active_games[ctx.channel.id].is_autostepping = True + await ctx.send("Starting auto-step at {0} per step...".format(datetime.timedelta(seconds=interval))) + while ctx.channel.id in hg.active_games and hg.active_games[ctx.channel.id].has_started: + ret = hg.step(ctx.channel.id, ctx.author.id) + if not await __check_errors(ctx, ret): + return + embed = discord.Embed(title=ret['title'], color=ret['color'], description=ret['description']) + if ret['footer'] is not None: + embed.set_footer(text=ret['footer']) + await ctx.send(embed=embed) + await asyncio.sleep(interval) + + +@bot.command +@commands.guild_only() +async def stopautostep(ctx): + # TODO: Fix this boilerplate spaghetti and fold it into the current error system + if ctx.channel.id not in hg.active_games: + __check_errors(ctx, ErrorCode.NO_GAME) + if hg.active_games[ctx.channel.id].owner_id is not ctx.author.id: + __check_errors(ctx, ErrorCode.NOT_OWNER) + if not hg.active_games[ctx.channel.id].has_started: + __check_errors(ctx, ErrorCode.GAME_NOT_STARTED) + if hg.active_games[ctx.channel.id].is_autostepping: + await ctx.reply("This game is not autostepping.") + return + hg.active_games[ctx.channel.id].is_autostepping = False + await ctx.send("Autostepping cancelled.") + + async def __check_errors(ctx, error_code): if type(error_code) is not ErrorCode: return True diff --git a/requirements.txt b/requirements.txt index cef2d54..1a32038 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py \ No newline at end of file +git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py +pytimeparse==1.1.7 \ No newline at end of file