async def dadjoke_task(channel): while True: # Looped until terminated if channel not in dadjokeChannels: # If task is found to not be signed up break # then end terminate. dadjoke = Dadjoke() await channel.send(dadjoke.joke) await asyncio.sleep(dadjokeInterval) # Interval is stored in setup.py
async def dadjoke(self, ctx): random_dadjoke = Dadjoke() embed = discord.Embed(color=self.bot.embed_color, title="→ Random Dad Joke!", description=f"• {random_dadjoke.joke}") await ctx.send(embed=embed) logger.info(f"Fun | Sent Dadjoke: {ctx.author}")
def play_joke(joke_group=None): if joke_group is None: joke_group = random.choice(list(overview.keys())) joke_sub_group = random.choice(overview[joke_group]) if "module." in joke_sub_group: _, joke_module = joke_sub_group.split(".") if joke_module == "dadjokes": dad_joke = Dadjoke() joke = dad_joke.joke if joke_module == "pyjokes": joke = pyjokes.get_joke() speak(joke) elif "sound." in joke_sub_group: _, sound_group = joke_sub_group.split(".") sound_files = sounds_overview[sound_group] sound_file = random.choice(sound_files) if "folder." in sound_file: _, sound_folder_path = sound_file.split(".") sound_folder_path = base_folder + "/sounds/" + sound_folder_path + "/*" files = glob.glob(sound_folder_path) if len(files) == 0: print("No files found", "Looking in ", sound_folder_path) return sound_file = random.choice(files) else: sound_file = base_folder + "/sounds/" + sound_file ext = sound_file.split(".")[-1] if ext != "wav": print("The sound file has to be a wav file") return play_sound(sound_file) else: with open(base_folder+"/"+joke_sub_group) as fp: jokes = fp.readlines() joke = random.choice(jokes) speak(joke)
async def on_message(message): if message.author == client.user: return message.content = message.content.lower() #greets user if message.content.startswith('hello') or message.content.startswith('hi'): await message.channel.send("Hello!\nEnter \"help\" for information!") return #tells a random dad joke if user sends a message containing phrase "joke" if 'joke' in message.content: dadjoke = Dadjoke() await message.channel.send(dadjoke.joke) return # tells "hi [], i'm dad" joke if (message.content.startswith('i\'m') or message.content.startswith('i am')): words = message.content.split(" ") words.pop(0) s = ' '.join(words) await message.channel.send(f"Hi {s.capitalize()}! I'm DadBot!") return # tells weather based on user-provided location if 'weather' in message.content: weather_dict = get_weather(message) await message.channel.send( f"{weather_dict['location']} : {weather_dict['weather']} and it's {weather_dict['temperature']}\xb0F today!" ) return # Sends help information to user if "help" in message.content: await message.channel.send( "Say hi to Your Dad Bot by saying Hi or Hello\nAsk for the weather. (Ex: What's the weather like in Orlando?)\nAsk me to tell a joke!\nAsk me for life advice/quotes!\nStart a sentence with \"I\'m\"" ) return # tells a random quote/advice if ("quote" or "advice" in message.content): quote = get_quote() await message.channel.send(quote) return
async def on_message(message): # Called whenever somebody sends a message if message.author == client.user: # ignore messages sent by client return if message.content.startswith("{}dadjoke".format(cmdPrefix)): # Dad joke handler if message.content.startswith("{}dadjoke toggle".format(cmdPrefix)): # Send occational dadjokes if message.channel not in dadjokeChannels: # If message channel is not in recipent list await message.channel.send("Now delivering dad jokes to this channel at an interval of {} seconds. :man:".format(dadjokeInterval)) # Pass channel identifier to the dadjoke task dadjokeChannels.append(message.channel) # Put channel in recipent list client.loop.create_task(dadjoke_task(message.channel)) # start dadjoke loop elif message.channel in dadjokeChannels: await message.channel.send("Dad to see you go.:wave:") dadjokeChannels.remove(message.channel) else: dadjoke = Dadjoke() await message.channel.send(dadjoke.joke) # Send random dad joke if (message.content.startswith("Is ") and message.content.endswith(" gay?")): recipent = GetRecipent(message.content) strings = [f'{recipent} is extremely gay right now', f'{recipent} is not gay right now.', f'{recipent} is gay right now.', f'{recipent} is extremely not gay af right now.'] await message.channel.send(random.choice(strings)) if message.content.startswith("{}u.gg ".format(cmdPrefix)): msgsliced = message.content.split(" ") champ = (msgsliced[1]) role = (msgsliced[2]) if champ.upper() in (champ.upper() for champion in champarray): url = 'http://u.gg/lol/champions/{}/build?role={}'.format(champ.lower(), role.lower()) await message.channel.send('Grabbing u.gg page for {}. I am sorry you have to go through this.'.format(champ.lower())) TakeScreenie_UGG(url) await message.channel.send('Current page for {}'.format(champ.lower()), file=discord.File("data/image.png")) else: await message.channel.send(('Champion name "{}" is invalid').format(champ.lower())) if message.content.startswith("{}christmas".format(cmdPrefix)): current_day = date.today() christmas = date(2019, 12, 24) delta = christmas - current_day print(delta) await message.channel.send(('{} days to christmas').format(str(delta.days))) if message.content.startswith("{}quit".format(cmdPrefix)): await client.logout() print("Logging off...")
async def dadjoke(self,ctx): """Gives a random Dadjoke""" x = Dadjoke() await ctx.send(x.joke)
# python modules import random import re import asyncio from datetime import date # Used for christmas command from PIL import Image # Used for image manupulation # imports league of legends champion names and servers and their assigned dadjoke channels from firstbot_database import champarray, dadjokeChannels from setup import * # Selenium webdriver setup from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from dadjokes import Dadjoke dadjoke = Dadjoke() print(dadjoke.joke) cap = DesiredCapabilities().FIREFOX cap["marionette"] = False geckodriver = 'geckodriver.exe' # Destination of webdriver (firefox) options = Options() options.headless = False # makes window invisible options.set_preference("browser.tabs.warnOnClose", False) # adblockpath = '/ublock_origin-1.21.2-an+fx.xpi' client = discord.Client() # END OF IMPORTS # @client.event
def __init__(self, bot): self.bot = bot self.jokes = Dadjoke() self.session = aiohttp.ClientSession()
def on_get(self, req, resp): dadjoke = Dadjoke() resp.media = dadjoke.joke
async def dadjoke(self, ctx): dadjoke = Dadjoke() await ctx.trigger_typing() await asyncio.sleep(3) await ctx.send(dadjoke.joke)
def dadjokes(): dadjokes = Dadjoke() joke = dadjokes.joke return render_template('dadjokes.html', dadjoke=joke)
async def djoke(self, ctx): dadjokes = Dadjoke() await ctx.send(dadjokes.joke)
async def joke(ctx): dadjoke = Dadjoke() joke = dadjoke.joke await reply("send", ctx.message, joke)