Skip to content

Commit

Permalink
refact(ttt): rename morpion to tictactoe in code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRunner committed Nov 18, 2023
1 parent ce76085 commit a4327db
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions events-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
}
},
"christmas-2023": {
"begin": "2023-12-01",
"begin": "2023-11-01",
"end": "2023-12-31",
"type": "christmas",
"icon": "https://zrunner.me/cdn/halloween_2023.png",
Expand All @@ -219,7 +219,7 @@
"points": 600,
"reward_type": "rankcard",
"rank_card": "christmas23",
"min_date": "2023-12-25"
"min_date": "2023-10-25"
}
],
"emojis": {
Expand Down Expand Up @@ -252,7 +252,7 @@
"lutin",
"cookie"
],
"probability": 0.1
"probability": 0.91
}
}
}
30 changes: 15 additions & 15 deletions fcts/morpions.py → fcts/tictactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from libs.serverconfig.options_list import options


class Morpions(commands.Cog):
class TicTacToe(commands.Cog):
"Allow users to play PvP tic-tac-toe"

def __init__(self, bot: Axobot):
self.bot = bot
self.file = 'morpions'
self.file = 'tictactoe'
self.in_game = {}
self.types: tuple[str] = options['ttt_display']['values']

Expand All @@ -37,13 +37,13 @@ async def main(self, ctx: MyContext, leave: Literal['leave'] = None):
"""
if leave == 'leave':
if ctx.author.id not in self.in_game:
await ctx.send(await self.bot._(ctx.channel, 'morpion.not-playing'))
await ctx.send(await self.bot._(ctx.channel, 'tictactoe.not-playing'))
else:
self.in_game.pop(ctx.author.id)
await ctx.send(await self.bot._(ctx.channel, 'morpion.game-removed'))
await ctx.send(await self.bot._(ctx.channel, 'tictactoe.game-removed'))
return
if ctx.author.id in self.in_game:
await ctx.send(await self.bot._(ctx.channel, 'morpion.already-playing'))
await ctx.send(await self.bot._(ctx.channel, 'tictactoe.already-playing'))
return
self.in_game[ctx.author.id] = time.time()
game = self.Game(ctx, self, await self.get_ttt_mode(ctx))
Expand All @@ -54,7 +54,7 @@ async def main(self, ctx: MyContext, leave: Literal['leave'] = None):
class Game():
"An actual tictactoe game running"

def __init__(self, ctx: MyContext, cog: 'Morpions', mode: Literal["disabled", "short", "normal"]):
def __init__(self, ctx: MyContext, cog: 'TicTacToe', mode: Literal["disabled", "short", "normal"]):
self.cog = cog
self.ctx = ctx
self.bot = ctx.bot
Expand Down Expand Up @@ -129,8 +129,8 @@ async def start(self):
try:
grille = list(range(1, 10))
tour = await self.player_starts()
u_begin = await self.bot._(ctx.channel, 'morpion.user-begin' if tour else 'morpion.bot-begin')
tip = await self.bot._(ctx.channel, 'morpion.tip', symb1=self.emojis[0], symb2=self.emojis[1])
u_begin = await self.bot._(ctx.channel, 'tictactoe.user-begin' if tour else 'tictactoe.bot-begin')
tip = await self.bot._(ctx.channel, 'tictactoe.tip', symb1=self.emojis[0], symb2=self.emojis[1])
await ctx.send(u_begin.format(ctx.author.mention) + tip)
match_nul = True

Expand All @@ -154,7 +154,7 @@ def check(msg: discord.Message):
try:
msg: discord.Message = await self.bot.wait_for('message', check=check, timeout=50)
except asyncio.TimeoutError:
await ctx.channel.send(await self.bot._(ctx.channel, 'morpion.too-late'))
await ctx.channel.send(await self.bot._(ctx.channel, 'tictactoe.too-late'))
return
saisie = msg.content
if msg.content in self.entrees_valides:
Expand All @@ -164,13 +164,13 @@ def check(msg: discord.Message):
if self.use_short:
await msg.delete(delay=0.1)
else: # cell is not empty
await ctx.send(await self.bot._(ctx.channel, 'morpion.pion-1'))
await ctx.send(await self.bot._(ctx.channel, 'tictactoe.pion-1'))
display_grille = False
continue
elif msg.content.endswith("leave"): # user leaves the game
return
else: # invalid cell number
await ctx.send(await self.bot._(ctx.channel, 'morpion.pion-2'))
await ctx.send(await self.bot._(ctx.channel, 'tictactoe.pion-2'))
display_grille = False
continue
###
Expand Down Expand Up @@ -203,12 +203,12 @@ def check(msg: discord.Message):
if self.use_short and last_grid:
await last_grid.delete()
if match_nul:
resultat = await self.bot._(ctx.channel, 'morpion.nul')
resultat = await self.bot._(ctx.channel, 'tictactoe.nul')
else:
if tour: # Le bot a gagné
resultat = await self.bot._(ctx.channel, 'morpion.win-bot')
resultat = await self.bot._(ctx.channel, 'tictactoe.win-bot')
else: # L'utilisateur a gagné
resultat = await self.bot._(ctx.channel, 'morpion.win-user', user=ctx.author.mention)
resultat = await self.bot._(ctx.channel, 'tictactoe.win-user', user=ctx.author.mention)
await ctx.send(await self.display_grid(grille)+'\n'+resultat)
if not match_nul and not tour:
# give event points if user won
Expand Down Expand Up @@ -236,4 +236,4 @@ async def give_event_points(self, channel, user: discord.User, points: int):


async def setup(bot):
await bot.add_cog(Morpions(bot))
await bot.add_cog(TicTacToe(bot))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a4327db

Please sign in to comment.