Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bye module #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import settings
import os
from modules import news, image

from modules import bye
import discord
from discord.ext import commands
from modules import xkcd
Expand Down Expand Up @@ -56,4 +56,11 @@ async def search_image(ctx, search_arg):
print(e)
await ctx.send("Sorry, something went wrong.")


@bot.command(name='bye')
async def get_bye(ctx):
userName = ctx.author.name
output = bye.process(userName)
await ctx.send(output)

bot.run(TOKEN)
11 changes: 11 additions & 0 deletions byes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"byes": [
"Have a good day, sir.",
"Bye to you as well sir.",
"It was my pleasure talking to you sir.",
"It's sad to see you leave.",
"Farewell sir ! I hope I will see you soon.",
"Goodbye sir.",
"See you later sir."
]
}
20 changes: 20 additions & 0 deletions modules/bye.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
from random import choice
from templates.text import TextTemplate

BYE_SOURCE_FILE = 'data/byes.json'


def process(userName):
output = {}
with open(BYE_SOURCE_FILE) as bye_file:
byes = json.load(bye_file)
byes_list = byes['byes']
message = TextTemplate(choice(byes_list)).get_message()
temp = str(message).replace('{', '').replace('}', '')
temp = temp.replace('\'text\':', '').replace('\'', '')
temp = temp.replace('\\n', '\n').replace('"', '')
temp = temp.replace('sir', userName)
output['output'] = temp
output['success'] = True
return output['output']