on_message -> commands
This commit is contained in:
parent
534013a7dc
commit
eaf1686c5d
7 changed files with 93 additions and 66 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import os
|
||||
import discord
|
||||
import asyncio
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import functools
|
||||
import asyncio
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from werewolf_game import Game as Werewolf_Game
|
||||
|
||||
|
||||
|
|
@ -12,54 +13,74 @@ if TOKEN is None:
|
|||
print("Missing discord token!")
|
||||
exit(1)
|
||||
|
||||
bot = discord.Client()
|
||||
bot = commands.Bot(command_prefix=commands.when_mentioned_or('$werewolf '))
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
await bot.change_presence(status=discord.Status.idle, activity=discord.Game('One Night Ultimate Werewolf'))
|
||||
print('We have logged in as {0.user}'.format(bot))
|
||||
|
||||
|
||||
|
||||
async def hello(message):
|
||||
print("Hello")
|
||||
await message.channel.send('Hello!:regional_indicator_a:')
|
||||
|
||||
print(message.mentions)
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
|
||||
global running
|
||||
|
||||
if message.author == bot.user:
|
||||
return
|
||||
await bot.process_commands(message)
|
||||
|
||||
|
||||
if message.content.startswith('$hello'):
|
||||
await hello(message)
|
||||
@bot.group(help="werewolf game", description="Prefix for the One Night Ultimate Werewolf commands.")
|
||||
async def game(ctx):
|
||||
if ctx.invoked_subcommand is None:
|
||||
await bot.say('Invalid sub command passed...')
|
||||
|
||||
|
||||
@game.command(help="start werewolf game", description="Start One Night Ultimate Werewolf game.")
|
||||
async def start(ctx):
|
||||
if werewolf_game.running:
|
||||
await ctx.message.channel.send("Sorry! A game is already running")
|
||||
return
|
||||
|
||||
werewolf_game.running = True
|
||||
werewolf_game.set_channel(ctx.message.channel)
|
||||
|
||||
if message.content.startswith('$logout'):
|
||||
await bot.logout()
|
||||
return
|
||||
await werewolf_game.game()
|
||||
|
||||
|
||||
if message.content.startswith('$werewolf'):
|
||||
|
||||
# start (only one instance running)
|
||||
|
||||
if werewolf_game.running:
|
||||
await message.channel.send("Sorry! A game is already running")
|
||||
return
|
||||
|
||||
werewolf_game.running = True
|
||||
werewolf_game.set_channel(message.channel)
|
||||
@bot.command(help="greets you", description="This just says hello back to the message author.")
|
||||
async def hello(ctx):
|
||||
await ctx.message.channel.send(f"Hello {ctx.message.author.name} :wave:")
|
||||
|
||||
|
||||
await werewolf_game.game()
|
||||
@bot.command(help="test bot responsiveness", description="This is a debug function to see if the bot listens to a command.")
|
||||
async def ping(ctx):
|
||||
print("pong")
|
||||
await ctx.send("pong")
|
||||
|
||||
|
||||
def developer(command):
|
||||
@functools.wraps(command)
|
||||
async def wrapper(ctx):
|
||||
DEV_ID = 461892912821698562
|
||||
if ctx.message.author.id == DEV_ID:
|
||||
await command(ctx)
|
||||
else:
|
||||
await ctx.send("This command is not for you!")
|
||||
return wrapper
|
||||
|
||||
|
||||
@bot.command(help="not for you", description="Shut down the bot.")
|
||||
@developer
|
||||
async def logout(ctx):
|
||||
await bot.logout()
|
||||
|
||||
|
||||
@bot.command(help="debug")
|
||||
@developer
|
||||
async def debug(ctx):
|
||||
print("DEBUG")
|
||||
print(ctx.message.author.id)
|
||||
|
||||
return
|
||||
|
||||
werewolf_game = Werewolf_Game(bot)
|
||||
bot.run(TOKEN)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue