async def joke(self, ctx): """Replies with a random joke""" joke = joke_api.get_joke() if joke == False: await ctx.send("Couldn't get joke from API. Try again later.") else: await ctx.send(joke['setup'] + '\n' + joke['punchline'])
async def on_message(message): if message.content.startswith('%joke'): # joke commands joke = joke_api.get_joke() print(joke) if joke == False: await message.channel.send( "Couldn't get joke from API. Try again later.") # joke failed else: await message.channel.send(joke['setup'] + '\n' + joke['punchline'])
async def on_message(message): if message.author == client.user: return if message.content.startswith('!joke'): joke = joke_api.get_joke() print(joke) if joke == False: await message.channel.send("Couldn't get joke from API. Try again later.") else: await message.channel.send(joke['setup'] + '\n' + joke['punchline'] ) await client.process_commands(message)
async def on_message(message): if (message.author == client.user): return msg = message.content if (msg.startswith('$hello')): await message.channel.send('Hello Paaji! Hows the josh ?') if (msg.startswith('$inspire')): quote = get_quote() await message.channel.send(quote) if db["responding"]: options = starter_encouragements if "encouragements" in db.keys(): options = options + db["encouragements"] if (any(word in msg for word in sad_words)): await message.channel.send(random.choice(options)) if (msg.startswith("$add")): encouraging_message = msg.split("$add ", 1)[1] update_encouragements(encouraging_message) await message.channel.send("Happy hojaao,message add hogya h aapka!") if (msg.startswith("$responding")): value = msg.split("$responding ", 1)[1] if (value.lower() == "false"): db["responding"] = False await message.channel.send("Bye bye tata sab khatam") else: db["responding"] = True await message.channel.send("Guru lo hogya mein shuru") if message.content.startswith('$joke'): joke = joke_api.get_joke() # print(joke) if joke == False: await message.channel.send( "Couldn't get joke from API. Try again later.") else: await message.channel.send( f"**{joke['setup']}**\n\n ||{joke['punchline']}||") if (msg.startswith('$weather')): city = msg.split("$weather ", 1)[1] weather = get_weather(city) await message.channel.send(weather["coord"]) await message.channel.send(weather["main"])
def cmdchecker(msg, message_author): #i think it's good to have this input format: # baje add chal #<category> #<title> #<decsription> # maile copy # # command = msg.split()[0].lower() ## command: hello/add/joke/chutkila try: type = msg.split()[1].lower() ## type: challenge(or chal)/flag/random/programming except IndexError: type = 'all' msg_new = msg.split('\n') print(msg_new) # for debugging purpose category = msg_new[1].strip() ## category: category for adding chals/ challenge id for flags title = msg_new[2].strip() ## title: title of challenge/ the flag description = '\n'.join(msg_new[3:]).strip() ## description of challenge response = '' try: if command == 'hello' or command == 'Hello': response = 'hello babu!' elif command == 'repeat': response = ' '.join(type) ## type = args[1], see above elif command == 'add': if type == 'challenge' or type == 'chal': response = add_challenge(message_author, category, title, description) elif type == 'flag': response = add_flag(category, title, message_author) elif command == 'submit': pass elif command == 'publish': #baje publish <challenge-id> => publish the challenge in #challenges_bot (channel to be renamed) # response = chal_function(challenge_id) #each and everything this command requires is in chal_function() implementation for search #but we need to make this command post challenges in #challenges (to be renamed from #challenges_bot) channel pass elif command == 'joke': response = joke_api.get_joke() elif command == 'chutkila': response = chutkila.get_chutkila() elif command == 'coronavirus' or command == 'corona' or command == 'covid' or command == 'covid19': try: # return the data for country the users type response = covid19_api.covid19_data_country(type) except: # return global data if no additional argument response = covid19_api.covid19_data_global() elif command == 'clear': #i think we shud make this clear feature to make it easier for us to clear files pass except: return "Oops! Some error occurred!" return response