Skip to content
Permalink
0ba52bc3a6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
158 lines (139 sloc) 6.33 KB
##########
## Discord Bot designed for the 4071 CEM Module for
## the Activity Led Project for Computer Science at Coventry University
##
## Utilises the Wiimmfi API to provide end-users with the ability
## to see online matches for Mario Kart Wii and other Wii Games on
## this custom server
##
## (C) Wiimmfi and it's subsidiaries by Wimm and Leseratte
## https://wiimmfi.de/
##
## (C) discord.py API https://discordpy.readthedocs.io/en/stable/index.html#
##
## (C) Discord API: https://discord.com/developers/docs/intro
##
## Copyright (C) 2022 Harry Clark - Student No. 12340530
##
##########
import os ## FETCH CONTENTS OF PRE-REQUISITIE FILES (JSON AND .ENV)
import discord ## DISCORD.PY API
from discord.ext import commands, tasks
from dotenv import load_dotenv
import random
import asyncio
##########
##
## This Function is for initialising the main functionality of the bot.
## Using the Discord API to declare the runtime for the Bot
##
##########
load_dotenv(".env")
TOKEN = os.getenv("TOKEN")
intents=discord.Intents.all() ## The new version of discord.py requires intents.
## This is to reduce bloat within the program; allowing the bot to be use specific events as opposed to all of them
## and for hardly any of them to be used
COMMAND_SYMBOL = "wiimmfi:"
BOT = commands.Bot(command_prefix=COMMAND_SYMBOL, intents=intents) ## uses a specific prefix to initiate the bot
BOT.remove_command('help')
##########
##
## Wiimmfi Variables
##D
##########
WIIMMFI_STATUS = "https://wiimmfi.de/stat?m=80"
WIIMMFI_REGION = "https://wiimmfi.de/reg-stat"
FACTS = ["Wiimmfi is a substitute server for the Nintendo WFC which was shut down on May 20th 2014",
"There are a lot of ways to download Wiimmfi onto your system. This can be through the propriatory Wiimmfi Patcher using the Homebrew Channel. Or, specifically for Mario Kart Wii, you can use CTGP",
"Wiimmfi began life on May 10th 2014, 10 days prior to the shutdown of WFC",
"The main developer, Wiimm, originally implemented the server using PHP due to it's ease of use with server side client hosting. However, to improve performance, the servers were re-written for C/C++"]
##########
##
## This section is just to provide the Bot with the required events for it's functionality
## In this context, I want to allow for the Bot to send message through basic commands using a pre-established prefix
##
## Provided help for this section is explicitly provided by the discord.py api https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.user
##
## I used this because when it comes to using the Developer Portal, there are a variety of options
## Therefore, allocating the provided events to the Bot as opposed to another other provided Clients will reduce compatibility issues
##
##########
@BOT.event
async def on_ready(): ## Using the API's pre-requisite function names for clarity
print('Bot is in use')
await BOT.change_presence(activity=discord.Game("4071 ALL PROJECT 1"))
@BOT.command(name='hello')
async def START_MESSAGE(ctx): ## uses ctx as part of the commands provided by the API https://discordpy.readthedocs.io/en/stable/ext/commands/commands.html
if ctx.author == BOT.user:
return
else:
await ctx.send("Hi! I'm the Wiimmfi Bot; here to provide information about the Wiimmfi server and it's services")
@BOT.command(name='status')
async def STATUS(ctx):
if ctx.author == BOT.user:
return
else:
await ctx.send("The status of the Wiimmfi servers are online, with the following games being supported: Mario Kart Wii, Mario Kart DS, Super Smash Bros Brawl and Pokemon Black and White")
await ctx.send("Currently, there are 170 people playing Mario Kart Wii with a total of 620k profiles made with the Wiimmfi server")
@BOT.command(name='region')
async def REGION(ctx):
if ctx.author == BOT.user:
return
else:
await ctx.send("There are a variety of regions as well as custom fun rooms made such as:")
await ctx.send("``Europe``")
await ctx.send("``Japan``")
await ctx.send("``America``")
await ctx.send("``Oceania``")
await ctx.send("``Taiwan``")
await ctx.send("``CTGP``")
@BOT.command(name='help')
async def HELP(ctx):
if ctx.author == BOT.user:
return
else:
await ctx.send("Help: Here are the variety of commands you can use to tell me what to do:")
await ctx.send("``Hello: Get the ball rolling with getting introduced to the bot``")
await ctx.send("``Status: tells you the status of the Server as well as how many people are online``")
await ctx.send("``Region: tells you which regions are online and where the rooms are``")
await ctx.send("``Fact: tells you a fact...``")
@BOT.event
async def on_message(MESSAGE):
if COMMAND_SYMBOL in MESSAGE.content:
print("Used a command") ## just for testing purposes in the terminal
await BOT.process_commands(MESSAGE)
@BOT.command(name='fact')
async def FACTS_FUNC(ctx):
if ctx.author == BOT.user:
return
else:
await ctx.send(random.choice(FACTS))
##########
##
## Base case provided for when the Bot closes
##
##########
@BOT.command()
async def LATENCY(ctx):
await ctx.send(round(BOT.latency * 1000))
##########
##
## This Function is provided to provide nuance to the rest of the program
## Used as part of Test Driven Development to discern any issues
## with the initilaising with the bot
##
## We use an asynchronous coroutine to allow for this process to run independantly from other processes
## This Function provides more scalibilty for being able to discern
## which processes occur first.
##
## CITED INFORMATION PROVIDED BY What is Asynchronous and What Does it Mean?
## What is Asynchronous and What Does it Mean?. (2022). Retrieved 25 October 2022, from https://www.techtarget.com/searchnetworking/definition/asynchronous##
##
##########
class ASYNC_INSTANCE:
async def __new__(WIIMMFI_BOT):
INSTANCE = super.__new__(WIIMMFI_BOT) ## Discerns a new asynchronous operation
return INSTANCE
async def __init__(self) -> None:
"ASYNCHRONOUS INSTANCE HAS BEEN INITILAISED"
BOT.run(TOKEN)