-
Notifications
You must be signed in to change notification settings - Fork 14
/
bot.py
114 lines (81 loc) · 3.52 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import logging
import os
from typing import Optional
import nextcord
from dotenv import load_dotenv
from nextcord.ext import commands
from utils import (
daily_puzzle_id,
generate_info_embed,
generate_puzzle_embed,
process_message_as_guess,
random_puzzle_id,
)
logging.basicConfig(level=logging.INFO)
load_dotenv()
activity = nextcord.Activity(type=nextcord.ActivityType.listening, name="/play")
bot = commands.Bot(command_prefix=commands.when_mentioned_or("w?"), activity=activity)
GUILD_IDS = (
[int(guild_id) for guild_id in os.getenv("GUILD_IDS", "").split(",")]
if os.getenv("GUILD_IDS", None)
else nextcord.utils.MISSING
)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
@bot.slash_command(name="play", description="Play Wordle Clone", guild_ids=GUILD_IDS)
async def slash_play(interaction: nextcord.Interaction):
"""This command has subcommands for playing a game of Wordle Clone."""
pass
@slash_play.subcommand(name="random", description="Play a random game of Wordle Clone")
async def slash_play_random(interaction: nextcord.Interaction):
embed = generate_puzzle_embed(interaction.user, random_puzzle_id())
await interaction.send(embed=embed)
@slash_play.subcommand(name="id", description="Play a game of Wordle Clone by its ID")
async def slash_play_id(
interaction: nextcord.Interaction,
puzzle_id: int = nextcord.SlashOption(description="Puzzle ID of the word to guess"),
):
embed = generate_puzzle_embed(interaction.user, puzzle_id)
await interaction.send(embed=embed)
@slash_play.subcommand(name="daily", description="Play the daily game of Wordle Clone")
async def slash_play_daily(interaction: nextcord.Interaction):
embed = generate_puzzle_embed(interaction.user, daily_puzzle_id())
await interaction.send(embed=embed)
@bot.slash_command(name="info", description="Wordle Clone Info", guild_ids=GUILD_IDS)
async def slash_info(interaction: nextcord.Interaction):
await interaction.send(embed=generate_info_embed())
@bot.group(invoke_without_command=True)
async def play(ctx: commands.Context, puzzle_id: Optional[int] = None):
"""Play a game of Wordle Clone"""
embed = generate_puzzle_embed(ctx.author, puzzle_id or random_puzzle_id())
await ctx.reply(embed=embed, mention_author=False)
@play.command(name="random")
async def play_random(ctx: commands.Context):
"""Play a random game of Wordle Clone"""
embed = generate_puzzle_embed(ctx.author, random_puzzle_id())
await ctx.reply(embed=embed, mention_author=False)
@play.command(name="id")
async def play_id(ctx: commands.Context, puzzle_id: int):
"""Play a game of Wordle Clone by its ID"""
embed = generate_puzzle_embed(ctx.author, puzzle_id)
await ctx.reply(embed=embed, mention_author=False)
@play.command(name="daily")
async def play_daily(ctx: commands.Context):
"""Play the daily game of Wordle Clone"""
embed = generate_puzzle_embed(ctx.author, daily_puzzle_id())
await ctx.reply(embed=embed, mention_author=False)
@bot.command()
async def info(ctx: commands.Context):
"""Info about Discord Wordle Clone"""
await ctx.reply(embed=generate_info_embed(), mention_author=False)
@bot.event
async def on_message(message: nextcord.Message):
"""
When a message is sent, process it as a guess.
Then, process any commands in the message if it's not a guess.
"""
processed_as_guess = await process_message_as_guess(bot, message)
if not processed_as_guess:
await bot.process_commands(message)
bot.run(os.getenv("TOKEN"))