async def math_func(message, client, arguments): if message.author.nick is None: name = message.author.name else: name = message.author.nick # Calling function nsp = nps.NumericStringParser() result = nsp.eval(arguments) # removing .0 when value is int try: b = ceil(result) if result == b: result = b except: pass # Checking for 69 if result == 69 or result == 69.69: eggplant = ":eggplant:" else: eggplant = "" # Creating message letter = ":cancer: **| {} it's {} {}**".format(name, str(result), eggplant) await client.send_message(message.channel, letter) send(1, "Math done")
async def joke(message, client, arguments): """# Starting to fetch a joke response = loads(rget("https://08ad1pao69.execute-api.us-east-1.amazonaws.com/dev/random_joke").text) # Creating letter letter = "**{}**\n-{}".format(response["setup"], response["punchline"]) # Sending message await client.send_message(message.channel, letter) send(1, "Joke sent LUL") # Old module # In the new module the jokes are with the bot """ # Getting jokes data = load(open('./jokes/joke_list.json')) # Getting a joke that's not too long for discord 2000 message limit asd = get_joke(data) # Generating message letter = ":joy: **| {}**\n`{}`".format(asd["title"], asd["body"]) await client.send_message(message.channel, letter) send(1, "Joke sent LUL")
async def add_users_new(): # Checking if client is ready and online await client.wait_until_ready() while not client.is_closed: info = [] count = 0 # Going through users for server in client.servers: for Member in server.members: # Adds info to the list info.append(Member.id) info.append( "" ) # TODO changed to cause id is identifier and name is not needed count += 1 # Creating and executing query if len(info) < 2: send( 1, "Your bot is so dead that it doesn't even have users to check OMG" ) return # Creating query and adding users query = "INSERT IGNORE INTO points_and_xp (d_id, name) VALUES {} ON DUPLICATE KEY UPDATE d_id=d_id;".format( ','.join(['(%s,%s)'] * count)) points_users_new_add(query, info) # sleeping for 60 seconds before running task again await asleep(60)
async def timer(message, client, arguments): # Checking for input try: arguments = str(arguments) time_to_sleep = int(arguments) except: await client.send_message(message.channel, ":x: **| Invalid input**") return # Starting process delete_this = await client.send_message( message.channel, ":clock1: **| <@{}> Notifying you in {} seconds!**".format( message.author.id, arguments)) send(1, "Asked for a timer") # after sleep removing previous message for chat clarity await asyncio.sleep(time_to_sleep) await client.delete_message(delete_this) # Sending message and logging await client.send_message( message.channel, ":clock1: **| <@{}> Time's up!**".format(message.author.id)) send(1, "Timer is done!") return
async def lmgtfy(message, client, arguments): # Query google = "<http://lmgtfy.com/?q={}>".format(quote(arguments)) # Sending message msg = await client.send_message(message.channel, "<@" + message.author.id + "> Let") await asyncio.sleep(0.5) await client.edit_message(msg, "<@" + message.author.id + "> Let me") await asyncio.sleep(0.5) await client.edit_message(msg, "<@" + message.author.id + "> Let me Google") await asyncio.sleep(0.5) await client.edit_message( msg, "<@" + message.author.id + "> Let me Google that") await asyncio.sleep(0.5) await client.edit_message( msg, "<@" + message.author.id + "> Let me Google that for") await asyncio.sleep(0.5) await client.edit_message( msg, "<@" + message.author.id + "> Let me Google that for you!\n" + google) send(1, "Lmgtfy processed!")
async def bank_interest(): # Checking if client is ready and online await client.wait_until_ready() while not client.is_closed: # Day, time(s) days start @ 0 sleep_this = time_format_new(BANK_INTEREST_DAY, BANK_INTEREST_TIME) send(2, "Interest in {}".format(sleep_this)) await asleep(sleep_this) users = [] # Mode_id=10, time="604800", time_type="SECOND" bank_update = get_users_lowest_bank_amount(10, "604800") for row in bank_update: # Split users between (updated this week) users.append(row[0]) # If no money in bank do nothing if row[1] != 0: # Calculating interest add_this_memes = int(mceil(row[1] * interest / 100)) # Checking if worth of adding if add_this_memes != 0: # Add memes for user user_add_points_in_bank(add_this_memes, row[0]) # Add logging points_stats_insert(message.server.id, row[0], 11, "Interest", "", "", "+" + str(add_this_memes), "", "Interest", "", "", "", 0, add_this_memes, 0) # If bank not updated this week get users' bank amount bank_nonupdate = get_users_bank_amount(users) # For each user for kek in bank_nonupdate: # Calculating interest add_this_memes = int(mceil(kek[1] * interest / 100)) # Checking if worth of adding if add_this_memes != 0: # Add memes for user user_add_points_in_bank(add_this_memes, kek[0]) # Add logging points_stats_insert(message.server.id, kek[0], 11, "Interest", "", "", "+" + str(add_this_memes), "", "Interest", "", "", "", 0, add_this_memes, 0)
async def lennyface(message, client, arguments): # Defining which lennyface to use number = randint(0, len(lennyfaces) - 1) # Sending lennyface await client.send_message(message.channel, lennyfaces[number]) send(1, "Lennyfac sent :)")
async def pun(message, client, arguments): #Starting to fetch a Catfact response = loads(rget("http://getpuns.herokuapp.com/api/random").text)["Pun"] # Sending message await client.send_message(message.channel, "<:honk:309227566680637441> **| {}**".format(response)) send(1, "Pun sent")
async def set_bot_playing(message, client, arguments): if message.author.id not in owners: return else: await client.change_presence(game=Game(name=arguments)) send(1, "Updating playing status!") return
async def chuck_norris(message, client, arguments): # Starting to fetch a joke response = loads(rget("http://api.icndb.com/jokes/random").text)["value"]["joke"] # Creating letter letter = "<@{}> **| {}**".format(message.author.id, response) # Sending message await client.send_message(message.channel, letter) send(1, "Chuck Norris joke sent!")
async def catfact(message, client, arguments): number = str(randint(1, 673)) url = "https://catfact.ninja/fact" fact = loads(rget(url).text) # Sending message letter = ":cat: **| {}**".format(fact["fact"]) await client.send_message(message.channel, letter) send(1, "Catfact received and sent!")
async def yo_mama(message, client, arguments): # Starting to fetch a joke url = loads(rget("http://api.yomomma.info/").text) response = loads(rget(url).text) # Creating letter letter = ":juggling: **| {}**".format(response["joke"]) # Sending message await client.send_message(message.channel, letter) send(1, "Joke received and sent!")
async def choose(message, client, arguments): # Choosing a random answer from given choices response = arguments[randint(0, len(arguments) - 1)] # Sending message to discord await client.send_message( message.channel, ":game_die: **| <@{}> {}**".format(message.author.id, response)) send(1, "Chose one") return
async def dad_joke(message, client, arguments): # Starting to fetch a joke response = loads(rget("https://icanhazdadjoke.com/slack").text) # Creating letter letter = "<@{}> **| {}**".format(message.author.id, response["attachments"][0]["text"]) # Sending message await client.send_message(message.channel, letter) send(1, "Dad joke sent") return
async def commands_help(message, client, arguments): starter = command_start if not arguments: function_commands = dirmap keepo = "**Here are all the commands!!!**\n" func_comd_list = [] for a in function_commands: if dirmap[a]["admin"] == False: func_comd_list.append(starter +a) keepo += "`" + ", ".join(func_comd_list) + "`" asd = commands_get_all() keepo += "\n\n**Here are all the response commands!!**\n" keepo += "`" + ", ".join(starter + b[0] for b in asd) + "`" if help_external_commands: for pod in help_external_commands: keepo += "\n\n**" + pod["commands_heading"] + "**\n" keepo += "`" + ", ".join(pod["command_start"] + b for b in pod["commands_list"]) + "`" try: if message.author.id in owners: keepo += "\n\n**Here are all the __ADMIN__ commands!!!** :smirk:\n" func_comd_list = [] for a in function_commands: if dirmap[a]["admin"] == True: func_comd_list.append(starter +a) keepo += "`" + ", ".join(func_comd_list) + "`" except: pass keepo += "\n\nFor more help do {}help <command>".format(starter) # Sending message await client.send_message(message.channel, keepo) else: # Getting command properties source = dirmap[arguments[0]] mail = "" # Getting pods for examples for pod in source["example"]: mail += "\n__Input:__ {}{}\n__Output:__ {}\n".format(starter, pod["input"], pod["output"]) # Creating message letter = "**:question: | Help menu for {}\n\n__INFO:__ {}\n__SYNTAX:__ {}{}\n{}**".format(arguments[0],source["info"],starter,source["syntax"],mail) # Sengind message await client.send_message(message.channel, letter) send(1, "Help sent!") return
async def tuplat(message, client, arguments): if len(arguments) == 0: # Getting stats user = message.author stats = users_get_roll_stats(message.author.id) else: user = await get_user_instance(message, arguments[0]) try: stats = users_get_roll_stats(user.id) except: send(1, "No user found") await client.send_message(message.channel, ":game_die: **| User not found!**") return # Name if user.nick is None: name = user.name else: name = user.nick # name user_mention = " for: " + name # Calculating winrate try: win_rate = mfloor(int(stats[1]) / int(stats[0]) * 100) except: win_rate = "0" # Memes if stats[2] == 0: memes = "" else: try: memes = "\n:money_with_wings: Memes gained: {}".format(mfloor(stats[2])) except: memes = "" # Tokens if stats[3] == 0: tokens = "" else: try: tokens = "\n:trophy: Tokens gained: {}".format(mfloor(stats[3])) except: tokens = "" # Creating message letter = ":game_die: **| Roll stats{}\n\n:arrows_counterclockwise: Rolled: {}\n:tada: Doubles: {}\n:thinking: Win-rate: {}%{}{}**".format(user_mention, stats[0], stats[1], win_rate, memes, tokens) await client.send_message(message.channel, letter)
async def ping(message, client, arguments): # Name if message.author.nick is None: name = message.author.name else: name = message.author.nick # Send message await client.send_message(message.channel, "**:poop: |{} Pong!**".format(name)) send(1, "Ping test command")
async def dogfact(message, client, arguments): #Starting to fetch a Catfact response = loads( rget("http://dog-api.kinduff.com/api/facts").text)["facts"][0] dog = [":dog:", ":dog2:"][randint(0, 1)] # Sending message await client.send_message(message.channel, "{} **| {}**".format(dog, response)) send(1, "Dogfact received and sent!") return
async def ip(message, client, arguments): ip_address = gethostbyname(arguments[0]) url = "https://ipinfo.io/%s/json".format(quote(ip_address)) response = loads(rget(url).text) letter = ":printer: **| We found info for your ip! ```IP: {}\ncity: {}\nregion: {}\ncountry: {}\nloc: {}\norg: {}```**" letter.format(response["ip"], response["city"], response["region"], response["country"], response["loc"], response["loc"]) # Send and log await client.send_message(message.channel, letter) send(1, "Ip info retrieved")
async def on_member_remove(member): # Getting room room_id = on_member_remove_room_id()[0] # If room exists if room_id: server = member.server fmt = 'Member {0.mention} left {1.name}!' channel = client.get_channel(room_id) await client.send_message(channel, fmt.format(member, server)) # Room doesn't exist else: send(1, "Member removed but remove room is not defined!")
async def on_member_join(member): # Getting room room_id = on_member_join_room_id()[0] # If room exists if room_id: server = member.server fmt = 'Welcome {0.mention} to {1.name}!' channel = client.get_channel(room_id) await client.send_message(channel, fmt.format(member, server)) #discord.Object(id='channel_id_here') # Room doesn't exist else: send(1, "Member joined but joined room is not defined!")
async def eight_ball(message, client, arguments): # Checking if message is the right length if len(message.content) > 8: # Choosing a random answer from choices respones = eightballresponses[randint(0, len(eightballresponses) - 1)] # Sending answer await client.send_message( message.channel, ":8ball: **| <@{}> {}**".format(message.author.id, respones)) send(1, "Eightballed") return
async def gender(message, client, arguments): #Starting to fetch a Catfact url = "https://api.genderize.io/?name={}".format(quote(arguments[0])) response = loads(rget(url).text) letter = ":alien: **| No data was found for {}!**".format(arguments[0]) # Checking if name is valid from response if response["gender"] != None: letter = ":alien: **| There's a {}% of {} being a {}!**".format(str(mceil(response["probability"] * 100)), response["name"].title(), response["gender"]) # Sending message await client.send_message(message.channel, letter) send(1, "Gendered :P") return
async def bitcoin(message, client, arguments): #Starting to fetch a Catfact url = 'https://api.coindesk.com/v1/bpi/currentprice.json' response = loads(rget(url).text) # Checking if name is valid from response # Sending message USD = "%.2f" % response["bpi"]["USD"]["rate_float"] GBP = "%.2f" % response["bpi"]["GBP"]["rate_float"] EUR = "%.2f" % response["bpi"]["EUR"]["rate_float"] letter = ":dollar: **| At the moment one Bitcoin is worth ```USD: ${}\nGBP: £{}\nEUR: €{}```**".format( USD, GBP, EUR) await client.send_message(message.channel, letter) send(1, "Bitcoin info sent")
async def random_cat(message, client, arguments): # Fetching data drom urban url = 'http://random.cat/meow' response = loads(rget(url).text)["file"] urlretrieve(response, "./download/cats/" + response[20:]) # Sending message await client.send_file(message.channel, "./download/cats/" + response[20:], filename="./download/cats/" + response[20:], content="<@" + message.author.id + "> ", tts=False) osremove("./download/cats/" + response[20:]) send(1, "Wild cat received!") return
async def weather(message, client, arguments): # Fetches weather send(1, "Fetching weather data") url = 'http://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s' % ( quote(arguments), apikey) data = loads(rget(url).text) # Formulating response DO NOT TOUCH WAS PAIN :) try: definition = data["name"] + "\nCurrently: " + data["weather"][0][ "description"] + "\nWind speed: " + str( data["wind"]["speed"]) + " m/s\nCurrent Temp: " + str( int(data["main"]["temp"] - 273.15)) + " °C / " + str( int((data["main"]["temp"] - 273.15) * 9 / 5 + 32) ) + " °F \nMax Temp: " + str( int(data["main"]["temp_max"] - 273.15) ) + " °C / " + str( int((data["main"]["temp_max"] - 273.15) * 9 / 5 + 32) ) + " °F \nMin Temp: " + str( int(data["main"]["temp_min"] - 273.15) ) + " °C / " + str( int((data["main"]["temp_min"] - 273.15) * 9 / 5 + 32) ) + " °F \nSunrise: " + datetime.fromtimestamp( data["sys"]["sunrise"]).strftime( '%Y-%m-%d %H:%M:%S' )[11:16] + "\nSunset: " + datetime.fromtimestamp( data["sys"]["sunset"]).strftime( '%Y-%m-%d %H:%M:%S' )[11:16] + "\nHumidity: " + str( data["main"]["humidity"] ) + " %" + "\nPressure: " + str( data["main"]["pressure"] ) + "00 Pa" + "\nLon: " + str( data["coord"] ["lon"]) + "°\nLat: " + str( data["coord"]["lat"]) + "°\n" response = "Weather in: " + data["name"] + ", " + data["sys"][ "country"] + "```" + definition + "```" except KeyError: response = "No match was found" # Sending message and logging await client.send_message(message.channel, ":earth_africa: **| {}**".format(response)) send(1, "Done with fetching weather data")
async def slap(message, client, arguments): # Tryiong to get user instance user = await get_user_instance(message, arguments[0]) if user is None: return # Creating author name author_name = author_nickanme(message.author) # Creating clients name client_name = author_nickanme(user) # Sending message letter = "**:raised_back_of_hand: | {} sla:b:s {}!**".format( author_name, client_name) await client.send_message(message.channel, letter) send(1, "Slapped")
async def strawpoll(message, client, arguments): # name if message.author.nick is None: name = message.author.name else: name = message.author.nick # Popping question to it's own variation question = arguments.pop(0) # Creating poll new_poll = create_poll(question, arguments) # Sending message letter = "**Here's your poll, {}**\n{}".format(name, new_poll.url) await client.send_message(message.channel, letter) send(1, "Strawpoll finished")
async def set_avatar(message, client, arguments): # Try parsing attachments try: url = message.attachments[0]["url"] except: url = arguments[0] # Get file name file_name = url.split("/")[len(url.split("/")) - 1].split("?")[0] # Checks Image url with open('./profile/bot_profile_pictures/{}'.format(file_name), 'wb') as handle: response = rget(url, stream=True) # Something went wrong if not response.ok: await client.send_message( message.channel, ":thinking: **| Invalid url or other error**") return # Saves image for block in response.iter_content(1024): handle.write(block) # Sending image with open('./profile/bot_profile_pictures/{}'.format(file_name), 'rb') as f: try: await client.edit_profile(avatar=f.read()) except: await client.send_message( message.channel, ":thumbsdown: **| Discord is not liking this try again later!**" ) return # Send info await client.send_message(message.channel, ":thumbsup: **| Profile picture updated!**") send(1, "Bot's profile picture updated!")
async def post_lotto_winner(): # Checking if client is ready and online await client.wait_until_ready() while not client.is_closed: keepo = time_format_new(raffle_selection_day, raffle_selection_time) send(1, "Sleeping for {} before Lotto!".format(keepo)) await asleep(keepo) # Get current week week = total_weeks() # TODO DEFINE SERVER winner_chicken_dinner = await select_random_user_from_lotto_by_server_by_week( client, "279619091055116291", week) # Do something when user is chosen print(winner_chicken_dinner.name)