-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (52 loc) · 2.03 KB
/
main.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
import logging
import os
from typing import Optional
import discord
import nextcord
from nextcord.ext import commands
from utils import generate_info_embed, generate_puzzle_embed, process_message_as_guess
logging.basicConfig(level=logging.INFO)
TOKEN = 'ma-token'
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(description="Play a game of Wordle Clone", guild_ids=GUILD_IDS)
async def play(
interaction: nextcord.Interaction,
puzzle_id: int = nextcord.SlashOption(
description="Puzzle ID, leave out for a random puzzle", required=False
),
):
# generate puzzle embed
embed = generate_puzzle_embed(interaction.user, puzzle_id)
# send the puzzle as an interaction response
await interaction.send(embed=embed)
@bot.command()
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)
await ctx.reply(embed=embed, mention_author=False)
@bot.slash_command(description="Info about Discord Wordle Clone", guild_ids=GUILD_IDS)
async def info(interaction: nextcord.Interaction):
await interaction.send(embed=generate_info_embed())
@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(TOKEN)