From 13064a3af0e231dc38241a9e9f702dbfbd68cc3f Mon Sep 17 00:00:00 2001 From: bibin Date: Wed, 15 Jul 2020 16:09:38 +0200 Subject: [PATCH] more refactoring --- .../__pycache__/developer.cpython-37.pyc | Bin 2695 -> 2736 bytes .../__pycache__/send_message.cpython-37.pyc | Bin 1068 -> 1068 bytes src/package/developer.py | 23 +++++----- .../games/__pycache__/game_cog.cpython-37.pyc | Bin 4787 -> 3939 bytes src/package/games/game_cog.py | 40 ++++++------------ .../werewolf/__pycache__/cog.cpython-37.pyc | Bin 1597 -> 2028 bytes src/package/games/werewolf/cog.py | 26 ++++++++++-- src/werewolf_bot.py | 2 +- 8 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/package/__pycache__/developer.cpython-37.pyc b/src/package/__pycache__/developer.cpython-37.pyc index 96d4ba4c2155bcf82fb38466472a322b1847f2b1..e2450da55a8698910161c1eae73e628e69caee7a 100644 GIT binary patch delta 755 zcmaJ-U279T6y3W!`;}yqZL-;#RIL)Q?n{f<50tLW^l9l>p%%3dlsC{VGks8@C0c$5v_hRCS78;bk?1h{7-*H&FfXgC zGquDS;bGx(rg6;E-AP*-`<){E$5Q)a z>B-dr`g3_Si6;FusbEnCf?1|Cy67OHJnljQ0R7 z@xiDNyy`jugG+6@2BG)8>NFJ7faSUTosS3$iXEC+FT*NSXW?E z{IWXG5M}%R246&_8Kt99IHtTUU;I3#^r+9GryN@^dg0eGT1VIrZ|%!ImRdkmORMXa p;S!G+;1TiJPMlkkn#~J*ORSYHxHnLTJLFpkhHy1cOiDg%{svoroiP9a delta 705 zcmZ9J&2G~`6ou#d-%i{(3HgDxq=?@LsX@>#pb`tjq6LA3U;)`gR%S??Cbl&Wt*9ck zQY&>!HHdZc28eEX1H=n>g?Is8fCYD)zydEm-8skS=z9FQa$0d8xvoR-dGjsb`E=&K zhmU8c%|oV7?HQp4HBZPfw4KG-qIP!9QHSPENIO5*kuJ;6faa+yeM~I<=Pc2}!YQ!A zz@r{5W=%y}dP$n))PBtN*f5G2KX~%0fBp;_ifCysuBBSSLYkT*mLz_UrH21*+>dyw zh5m>&6|Upz;+I-6^*$R8BTszQmc_bOJ={iPOejpq00xTWRGpC>LdiBcRsp?C(@`j9VK3JZsTJ*qjCTT>dVU-agRVagqOcQ$Z==*& z4w6ph^NI|V5sPhkO%(OAnCg1t0;-9DAj%5V;b7_CC9KCm*b}>IT*~sP63}@E%;T1U z{gmxp5_zp9zUx~TYuLhN*Bqvt)(~swSBwt;Rq@5#fwK5*)^A=$xoKxt$7L+leBMj= zEgakSK7IllMT4L%wyX`fE@G?eX6vhqg!p0IfK6fASD_?s+fVPLW;Ys*{E+fGR`6Ac zhV0e5eb(L0*5G%gdQW0Q967ZWuHr2JUQ$I^pedGG(ml;HEJOUX1NVXS6a)eOP`q|l PbN6x1Vt77sTCn*CUa+Lk diff --git a/src/package/__pycache__/send_message.cpython-37.pyc b/src/package/__pycache__/send_message.cpython-37.pyc index b5974d7a1ef0f77359e99f19442f302a2e81b191..96a6f4f6649e3cce1b629e7fca42bc635af13a73 100644 GIT binary patch delta 19 ZcmZ3(v4(@oiI-OY~cF0 zxfcAhX&C>YhskAQ@HuYv6b&~z24~z%Sl{fJeXC0)w*Q}bfpJ2U+zM5PX2A|_r1sY*=7=W9cbu3{EXWQWBUjdri zFYS)Y9qzs~It||79(q9K%jlQ*3U8uc<}JR8eub~`b@WZX!8g&j_%*(TewAP6H_)%~ zoBS5~b-vASqu<~=py{pBBi({1J1Ty>NLZAFN@>2N(BQMw?+()_k7)qn@?+uC=QVTp zl*osJ2Sna|e;`FYic>vk-}n1roF*gxI8@+NL?=Q{*Hhrmqc4LfQ4!HY7xi>M!mZvx zGiGBWFvccYmYccNv&Tk{bE6Nbo;~AvGGJBhtxzO zBE9LNo?PVbxYhe;#;gahJ$BNNcgDtw*e%zxc&-oYBO9Vfty7 z`}&ytk;r!exlzBAEv#KGD>C0xnWaZv!qzDef`Q2s$C<>+ny3!gaF7Me&L$;g+(G>xIV zt>MT`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V2%FbsnBKjt`pL*d)<`s~l zAd=bIWQjufB)hf?{S0J8vOr;@L@Ky-!YiRV+f&7%OtLF9ootw!6TLI$*;LkEw)z#x zj#V*t6p5_<(0dAcJBqGTJWCP%@wVk)Pl|54s;;uMzojNoi`4Z-=^=7Aqo{jAxch+& z%d!19hPH`;MFI(&$j6+ox2ZYH985zjI`2;~z~oLd*7Yqs#a~m;E&$hDnD5Z+Zo8)5 zqNT{w6>%4Jg$hnq*Qxd{728zIcH+{|4rX2kmcpO@Gv_*9eSv5{EEBsRvI zs3FgsQd}ewJXxpNSIc|Sc~Vx($)C^3xV0c-IblJC1EM<8}I4a<^md?K<>KC zF@Av$)rVAkM8z_nAR7Mw&%`J6npray^)B}b2P5bE1dOVhHy%ZWD;&grcKDOIf*2`c zXOkShaHb|CeT66aFKnNv?K$V5NReODTBX%roP+lUqo0}-MUk1&_l=k4Dc$w7mmq!f zw?8(2T##B1h>alE_+TiaZO^QR%_XlCL(0Lr=g5p$oW{c^By?dqxB{)ui%r8_P`Ec5 z4h83>HuEtC9@D}^c@alpGm84!8yt^w)7$eEX)3RzCqo<%-!zJZ(kQPR9i$sYg5^yn zilu8ST9R>cRL{+w_<-*b9H!YWd8=h|<+VG-jpx_&e-u7;%WUdRvxWz6d+V+BYwNB5 E0M2EN=Kufz diff --git a/src/package/games/game_cog.py b/src/package/games/game_cog.py index b530cff..27c5e4a 100644 --- a/src/package/games/game_cog.py +++ b/src/package/games/game_cog.py @@ -1,25 +1,23 @@ -"""This (abstract) module is a template for Discord Cog's for game specific channel commands""" +"""Has a single class: Game_cog""" # standard library imports -from typing import Dict +from typing import Dict, Type # discord imports import discord -from discord.ext import commands # local imports from ..send_message import Send_message from .game import Game -# TODO: take group as argument to add subcommands - -class Game_cog(Send_message, commands.Cog): +class Game_cog(Send_message): """This (abstract) class is are common function for the Game Cog's (setup-game, pre-game, in-game), mainly has checker functions""" - def __init__(self, bot, game_instances: Dict[discord.TextChannel, Game]): + def __init__(self, bot, game_cls: Type[Game]): self.bot = bot - self.game_instances = game_instances + self.game_cls = game_cls + self.game_instances = Dict[discord.TextChannel, self.game_cls] async def setup_check(self, ctx): if ctx.channel not in self.game_instances: @@ -36,17 +34,13 @@ class Game_cog(Send_message, commands.Cog): await self.send_wrong(ctx, "No game is running") return self.game_instances[ctx.channel].running - -class Setup_game_cog(Game_cog): - """This (abstract) class is a template for Discord Cog's for game specific channel commands for setting up the channel""" - - async def setup(self, ctx, game: Game): + async def setup(self, ctx): """This function creates an game instance for this channel""" if ctx.channel in self.game_instances: - await self.send_wrong(ctx, f"A game '{game.name}' is already setup in this channel") + await self.send_wrong(ctx, f"A game '{self.game_cls.name}' is already setup in this channel") else: - self.game_instances[ctx.channel] = game(self.bot, ctx.channel) - await self.send_friendly(ctx, f"This channel can now play: {game.name}") + self.game_instances[ctx.channel] = self.game_cls(self.bot, ctx.channel) + await self.send_friendly(ctx, f"This channel can now play: {self.game_cls.name}") async def reset(self, ctx): """This function deletes the game instance for this channel""" @@ -54,10 +48,10 @@ class Setup_game_cog(Game_cog): del self.game_instances[ctx.channel] # TODO: better info message - async def info(self, ctx, game: Game): + async def info(self, ctx): """Send information about the subcommands for the game""" embed = discord.Embed(title="How to play?", description="You will need to set up the game and its information in a channel and start the game there. Afterwards the player mainly interact with the bot in DM.", color=0x00ffff) - embed.set_author(name=f"With this bot you can play {game.name}") + embed.set_author(name=f"With this bot you can play {self.game_cls.name}") # embed.set_thumbnail(url="https://images-na.ssl-images-amazon.com/images/I/717GrDtFKCL._AC_SL1000_.jpg") embed.add_field(name="$w game setup", value="Make this channel playable.", inline=False) embed.add_field(name="$w game players", value="Set mentioned users as players", inline=False) @@ -66,10 +60,7 @@ class Setup_game_cog(Game_cog): embed.set_footer(text="Have fun!") await ctx.send(embed=embed) - -class Pre_game_cog(Game_cog): - """This (abstract) class is a template for Discord Cog's for game specific channel commands for setting up the game rounds""" - async def cog_check(self, ctx): + async def pre_game_check(self, ctx): return self.setup_check(ctx) and self.not_running_check(ctx) async def players(self, ctx): @@ -79,10 +70,7 @@ class Pre_game_cog(Game_cog): self.game_instances[ctx.channel].game = self.bot.loop.create_task(self.game_instances[ctx.channel].round()) await self.game_instances[ctx.channel].game - -class In_game_goc(Game_cog): - """This (abstract) class is a template for Discord Cog's for game specific channel commands during the game""" - async def cog_check(self, ctx): + async def in_game_check(self, ctx): return self.setup_check(ctx) and self.running_check(ctx) async def stop(self, ctx): diff --git a/src/package/games/werewolf/__pycache__/cog.cpython-37.pyc b/src/package/games/werewolf/__pycache__/cog.cpython-37.pyc index e3673ed4b1c9e330168b7b486239048bf91f7941..5ddac64b75f66da201e15a39a265b775da6eed03 100644 GIT binary patch delta 573 zcmZ8cJ!>055ZyWL-pPvYPL_p5Oc1BwAdVOpcEFtpiE#)9H7N|&9EWyK{y6K*-USmk zE+lXl5c>zDGU2S^TmJ~p>Z3?znb|k&!^_@Of4*do%5H-{a z-QL}hqI;a>LS|l+B;J|m<;Q7HaPK^czUXS4N-sYWUN<@uZQqc~D05=XS@o4Ru2!+q z)Zz^cgkIJTg%lTQ5{I3%yE*UdOiASR4e0mi8O6W>)f$&;Ssuw8Rd_P}+~Zyvdl&P6 z+S0*3oL$CC+B)dMEV!=`PT2Hy3*kaV^&b^e+Fw?G=;2G&ITD>ysb>eyxfG#ZEu0ng zF0!uH+16?mVG(Gd#%9NaHD-e1tkukozA*+MoS<}Q`-O=Wajw^umj1w0H>|O;iEyR{ YWDRlKUs8YB2AdS#r(H$O9i#T@3G7sZ{{R30 delta 215 zcmaFEzn4ediI;=lk4kl_Ht#SRnIjd_}xqu5e7QaD=}qSz;9 zd2@keL7+Hg;{JH9b_N!PDDGeeO`gpujP8t#Jd@Wj9cL7rT*7>SQEc)@7RkweEQ=VW zfh;*DO`gdfY~hoSvgz@GEazZkVG>~l!O5KL>M|(|%}fg!85vR-fTl6}X)@hnPfSUP oPtH#-VxJtyE+?!AvXlvAHDi$oko42!nB2s!GkG(+Ig@|{0N!jW#Q*>R diff --git a/src/package/games/werewolf/cog.py b/src/package/games/werewolf/cog.py index 87618b2..65b88ca 100644 --- a/src/package/games/werewolf/cog.py +++ b/src/package/games/werewolf/cog.py @@ -1,3 +1,5 @@ +"""Has a single class: Werewolf_Cog""" + # discord imports from discord.ext import commands @@ -6,12 +8,12 @@ from ..game_cog import Game_cog from .game import Werewolf_game -class Werewolf_cog(Game_cog): +class Werewolf_cog(Game_cog, commands.Cog): """This singleton class is a Discord Cog for the interaction in the werewolf game""" @commands.group(invoke_without_command=True) async def werewolf(self, ctx): - # TODO: isn't there a better way to have a default subcommand? + # TODO: isn't there a better way to have a default subcommand? Maybe invoke super().info()? await ctx.invoke(self.bot.get_command('werewolf info')) @werewolf.command() @@ -29,6 +31,24 @@ class Werewolf_cog(Game_cog): """This function deletes the game instance for this channel""" await super().reset(ctx) + @werewolf.command() + @commands.check(Game_cog.pre_game_check) + async def players(self, ctx): + """registers all mentioned players for the game""" + await super().players(ctx) + + @werewolf.command() + @commands.check(Game_cog.pre_game_check) + async def start(self, ctx): + """starts a round of werewolf""" + await super().start(ctx) + + @werewolf.command() + @commands.check(Game_cog.in_game_check) + async def stop(self, ctx): + """aborts the current round of werewolf""" + await super().stop(ctx) + def setup(bot): - bot.add_cog(Werewolf_cog(bot, None)) + bot.add_cog(Werewolf_cog(bot, Werewolf_game)) diff --git a/src/werewolf_bot.py b/src/werewolf_bot.py index c4b0ca0..9fb47b9 100644 --- a/src/werewolf_bot.py +++ b/src/werewolf_bot.py @@ -31,7 +31,7 @@ bot.load_extension('package.games.werewolf.cog') @bot.command() @commands.is_owner() async def reload(ctx, extension): - bot.reload_extension(f'{extension}') + bot.reload_extension(f'package.{extension}') # checker annotations