Created
September 11, 2018 17:02
-
-
Save IAmJSD/4491a1cc00d66efe5dddf0c4a8dd532d to your computer and use it in GitHub Desktop.
A Gordon Ramsay style bot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import random | |
import logging | |
import os | |
# Imports go here. | |
ramsay_quotes = [ | |
"YOU FUCKING DONKEY!", | |
"What are you? AN IDIOT SANDWICH.", | |
"GET OUT!", | |
"WHERE'S THE LAMB SAUCE?" | |
] | |
# A list of Ramsay quotes. | |
logging.basicConfig(level=logging.INFO) | |
# Sets up logging. | |
clean_message = lambda x: [ | |
y for y in x.strip(" ").split(" ") if y != "" and f"{client.user.id}" not in y | |
] | |
# Turns message into list and cleans of white space and the bot user. | |
mentions_to_ids = lambda y: [x.id for x in y] | |
# Converts mentions to IDs. | |
ramsayified_punctuation = lambda x: x.replace(".", ", you fucking donkey.").replace("!", ", FUCK OFF!") | |
# Ramsay-ifies the punctuation. | |
client = discord.Client() | |
# Defines the client. | |
def ramsayified_message(content): | |
count = 0 | |
new_split = [] | |
for x in content.split(" "): | |
if count == 2: | |
count = 0 | |
new_split.append(random.choice(["fuck off", "fucking", "dickhead", "you idiot sandwich"])) | |
else: | |
count += 1 | |
new_split.append(x) | |
return ramsayified_punctuation(" ".join(new_split)) | |
# Ramsay-ifies the message. | |
async def ramsay_quote(message): | |
try: | |
await message.channel.send(random.choice(ramsay_quotes)) | |
except (discord.NotFound, discord.Forbidden): | |
# YOU FUCKING DONKEY! | |
pass | |
# Tries to send a Ramsay quote. | |
async def ramsayify(message, content): | |
ramsayified_content = ramsayified_message(content) | |
try: | |
await message.channel.send(ramsayified_content) | |
except (discord.NotFound, discord.Forbidden): | |
# YOU FUCKING DONKEY! | |
pass | |
# The full ramsay-fying. | |
@client.event | |
async def on_message(message): | |
if client.user.id not in mentions_to_ids(message.mentions): | |
# Nope, not our problem. | |
return | |
content_split = clean_message(message.content) | |
# Gets a clean and split version of the message. | |
if len(content_split) == 0: | |
# We return a Ramsay quote. | |
return await ramsay_quote(message) | |
await ramsayify(message, " ".join(content_split)) | |
# The router for on_message. | |
client.run(os.environ["BOT_TOKEN"]) | |
# Starts the bot. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment