SHARE
TWEET

luckybot code

luckytyphlosion Nov 5th, 2015 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import discord
  3. import logging
  4. import random
  5. import json
  6. import math
  7.  
  8. slots_data = {}
  9.  
  10. nodecimal = lambda x: ("%s" % (x))[:-2]
  11.  
  12. def slots_calcpoints(level):
  13.         if level >= 12.1:
  14.                 level = 42069 ** (1/math.log10(level))
  15.         elif level == 1:
  16.                 level = 42069
  17.         else:
  18.                 temp_value = int(math.sqrt(-69420 * (level-69)))
  19.                 level = 6.9 * temp_value
  20.                
  21.         level = round(level)
  22.         return level
  23.        
  24. def add_user(username):
  25.         slots_data[username] = {
  26.         "slots_cooldown": time.time(),
  27.         "slots_wins": 0,
  28.         "slots_tries": 0,
  29.         "slots_executions": 0,
  30.         "slots_points": 0,
  31.         }
  32.  
  33. def save_slots():
  34.         temp_data = slots_data
  35.        
  36.         with open('slots_data.json', 'w') as fp:
  37.                 json.dump(temp_data, fp, sort_keys = True)
  38.        
  39. def load_slots():
  40.         with open('slots_data.json', 'r') as fp:
  41.                 slots_data = json.load(fp,)
  42.         return slots_data
  43.                
  44. def slots_updatetime(username):
  45.         slots_data[username]["slots_cooldown"] = time.time()
  46.        
  47. def slots_updatewins(username):
  48.         slots_data[username]["slots_wins"] += 1
  49.  
  50. def slots_updatetries(username,tries):
  51.         slots_data[username]["slots_tries"] += tries
  52.        
  53. def slots_updateexecutions(username):
  54.         slots_data[username]["slots_executions"] += 1
  55.        
  56. def slots_updatepoints(username,amount):
  57.         slots_data[username]["slots_points"] += amount
  58.        
  59. luckymsgs = []
  60. animationmsgs = []
  61. disablespam = [True]
  62.  
  63. """
  64. FORMAT: Username, Cooldown, number of first try wins, total tries, total command executions, performance
  65. """
  66.  
  67. # Set up the logging module to output diagnostic to the console.
  68. logging.basicConfig()
  69.  
  70. client = discord.Client()
  71. client.login('yellow151@memebig.net', 'KappaRoss42069') # username/password
  72.  
  73. if not client.is_logged_in:
  74.         print('Logging in to Discord failed')
  75.         exit(1)
  76.  
  77. @client.event
  78. def on_ready():
  79.         print('Connected!')
  80.         print('Username: ' + client.user.name)
  81.         print('ID: ' + client.user.id)
  82.         print('------')
  83.         global slots_data
  84.         slots_data = load_slots()
  85.         print(slots_data)
  86.         """
  87.         for server in client.servers:
  88.                 print(server.name)
  89.                 if server.name != "PokemonSpeedruns":
  90.                         continue
  91.                 for channel in server.channels:
  92.                         print(channel.name)
  93.                         if channel.name != bot_channel:
  94.                                 continue
  95.                         for role in server.roles:
  96.                                 client.send_message(channel,role.name)
  97.         """
  98. permissions = ["botowner","admin","moderator","user"]
  99.  
  100. def cmd_luckypls(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  101.         if len(luckymsgs) >= 1:
  102.                 if saved_message.content == "!luckyplsperma" and author != "luckytyphlosion":
  103.                         Kappa = ""
  104.                         for count in range(3):
  105.                                 Kappa += "Kappa "
  106.                                 client.send_message(saved_message.channel, Kappa)
  107.                         for count in range(2):
  108.                                 Kappa = Kappa[:-6]
  109.                                 client.send_message(saved_message.channel, Kappa)
  110.                 else:
  111.                         for message in luckymsgs:
  112.                                 if message.channel != saved_message.channel:
  113.                                         continue
  114.                                 else:
  115.                                         client.edit_message(message, "<message deleted>")
  116.                        
  117.                         if saved_message.content == "!luckyplsperma" and author == "luckytyphlosion":
  118.                                 pass
  119.                         else:
  120.                                 time.sleep(6.9)
  121.                                 for message in luckymsgs:
  122.                                         if message.channel != saved_message.channel:
  123.                                                 continue
  124.                                         else:
  125.                                                 client.edit_message(message, message.content)
  126.        
  127. def cmd_test(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  128.         client.send_message(message.channel, "icicles")
  129.        
  130. def cmd_yolocoin(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  131.         client.send_message(message.channel, "Congratulations on the new RIP!")
  132.  
  133. def cmd_animation(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  134.         luckypls = "!luckypls"
  135.         tempstring = " _ _ "
  136.         anim_msg = client.send_message(message.channel, luckypls)
  137.         for count in range(10):
  138.                 luckypls = tempstring + luckypls + tempstring
  139.                 anim_msg = client.edit_message(anim_msg, luckypls)
  140.                
  141.         for count in range(10):
  142.                 luckypls = luckypls[5:-5]
  143.                 anim_msg = client.edit_message(anim_msg, luckypls)
  144.        
  145. def cmd_scrolltext(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  146.         scrollmsg = queries[0]
  147.         sentmsg = client.send_message(saved_message.channel, "_ _")
  148.         deltamsg = ""
  149.         for char in scrollmsg:
  150.                 deltamsg += char
  151.                 anim_msg = client.edit_message(sentmsg, deltamsg)
  152.  
  153. def cmd_wall(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  154.         if not disablespam[0]:
  155.                 wall = ""
  156.                 wallargs = queries[0]
  157.                 count = 1
  158.                 for char in wallargs:
  159.                         if char == " ":
  160.                                 break
  161.                         else:
  162.                                 count += 1
  163.                                
  164.                 size = int(wallargs[:count])
  165.                 wallargs = wallargs[count:]
  166.                
  167.                 if wallargs:
  168.                         for count in range(size):
  169.                                 client.send_message(saved_message.channel, wallargs)
  170.                 else:
  171.                         client.send_message(saved_message.channel, "No sending null messages!")
  172.        
  173. def cmd_pyramid(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  174.         if not disablespam[0]:
  175.                 pyramid = ""
  176.                 pyramidargs = queries[0]
  177.                 count = 1
  178.                 for char in pyramidargs:
  179.                         if char == " ":
  180.                                 break
  181.                         else:
  182.                                 count += 1
  183.                                
  184.                 size = int(pyramidargs[:count])
  185.                 pyramidargs = pyramidargs[count:]
  186.                 if pyramidargs:
  187.                         for count in range(size):
  188.                                 pyramid += pyramidargs + " "
  189.                                 client.send_message(saved_message.channel, pyramid)
  190.                         for count in range(size-1):
  191.                                 pyramid = pyramid[:-(len(pyramidargs)+1)]
  192.                                 client.send_message(saved_message.channel, pyramid)
  193.        
  194. def cmd_funkytext(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  195.         scrollmsg = queries[0]
  196.         tempstring = " "
  197.         deltamsg = "_ _"
  198.         somemsg = client.send_message(saved_message.channel,"_ _")
  199.         for count in range(5):
  200.                 some_count = 0
  201.                 for char in scrollmsg:
  202.                         deltamsg = tempstring * some_count + char + tempstring * (len(scrollmsg) - some_count)
  203.                         client.edit_message(somemsg, deltamsg)
  204.                         some_count += 1
  205.                        
  206.         client.edit_message(somemsg, scrollmsg)
  207.        
  208. def cmd_enablespam(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  209.         disablespam[0] = False
  210.        
  211. def cmd_disablespam(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  212.         disablespam[0] = True
  213.        
  214. def cmd_slots(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  215.         if not checkForProfile():
  216.                 add_user(author)
  217.                        
  218.         if saved_message.channel.name == bot_channel and ((time.time() - (slots_data[author]["slots_cooldown"]) >= 180) or (slots_data[author]["slots_executions"] == 0)):
  219.                
  220.                 debugcount = 1
  221.                 while True:
  222.                         sampled_emotes = random.sample([":bowtie:",":smile:",":laughing:",":blush:",":smiley:",":relaxed:",":smirk:",":heart_eyes:",":kissing_heart:",":kissing_closed_eyes:",":flushed:",":relieved:",":satisfied:",":grin:",":wink:",":stuck_out_tongue_winking_eye:",":stuck_out_tongue_closed_eyes:",":grinning:",":kissing:",":kissing_smiling_eyes:",":stuck_out_tongue:",":sleeping:",":worried:",":frowning:",":anguished:",":open_mouth:",":grimacing:",":confused:",":hushed:",":expressionless:",":unamused:",":sweat_smile:",":sweat:",":disappointed_relieved:",":weary:",":pensive:",":disappointed:",":confounded:",":fearful:",":cold_sweat:",":persevere:",":cry:",":sob:",":joy:",":astonished:",":scream:",":neckbeard:",":tired_face:",":angry:",":rage:",":triumph:",":sleepy:",":yum:",":mask:",":sunglasses:",":dizzy_face:",":imp:",":smiling_imp:",":neutral_face:",":no_mouth:",":innocent:",":alien:",":yellow_heart:",":blue_heart:",":purple_heart:",":heart:",":green_heart:",":broken_heart:",":heartbeat:",":heartpulse:",":two_hearts:",":revolving_hearts:",":cupid:",":sparkling_heart:",":sparkles:",":star:",":star2:",":dizzy:",":boom:",":collision:",":anger:",":exclamation:",":question:",":grey_exclamation:",":grey_question:",":zzz:",":dash:",":sweat_drops:",":notes:",":musical_note:",":fire:",":hankey:",":poop:",":shit:",":+1:",":thumbsup:",":-1:",":thumbsdown:",":ok_hand:",":punch:",":facepunch:",":fist:",":v:",":wave:",":hand:",":raised_hand:",":open_hands:",":point_up:",":point_down:",":point_left:",":point_right:",":raised_hands:",":pray:",":point_up_2:",":clap:",":muscle:",":metal:",":fu:",":runner:",":running:",":couple:",":family:",":two_men_holding_hands:",":two_women_holding_hands:",":dancer:",":dancers:",":ok_woman:",":no_good:",":information_desk_person:",":raising_hand:",":bride_with_veil:",":person_with_pouting_face:",":person_frowning:",":bow:",":couplekiss:",":couple_with_heart:",":massage:",":haircut:",":nail_care:",":boy:",":girl:",":woman:",":man:",":baby:",":older_woman:",":older_man:",":person_with_blond_hair:",":man_with_gua_pi_mao:",":man_with_turban:",":construction_worker:",":cop:",":angel:",":princess:",":smiley_cat:",":smile_cat:",":heart_eyes_cat:",":kissing_cat:",":smirk_cat:",":scream_cat:",":crying_cat_face:",":joy_cat:",":pouting_cat:",":japanese_ogre:",":japanese_goblin:",":see_no_evil:",":hear_no_evil:",":speak_no_evil:",":guardsman:",":skull:",":feet:",":lips:",":kiss:",":droplet:",":ear:",":eyes:",":nose:",":tongue:",":love_letter:",":bust_in_silhouette:",":busts_in_silhouette:",":speech_balloon:",":thought_balloon:",":feelsgood:",":finnadie:",":goberserk:",":godmode:",":hurtrealbad:",":rage1:",":rage2:",":rage3:",":rage4:",":suspect:",":trollface:"],16)
  223.                
  224.                         slots = []
  225.                                
  226.                         for count in range(3):
  227.                                 slots.append(random.choice(sampled_emotes))
  228.                                
  229.                         if slots[0] == slots[1] and slots[1] == slots[2]:
  230.                                 slotsmsg = taguser() + "%s | %s | %s" % (slots[0],slots[1],slots[2])
  231.                                
  232.                                 newpoints = slots_calcpoints(debugcount)
  233.                                 slots_updatepoints(author, newpoints)
  234.                                
  235.                                 nodecimal_msg = nodecimal(newpoints)
  236.                                
  237.                                 slotsmsg += " Number of tries: %s. Points won: %s" % (debugcount,nodecimal_msg)
  238.                                
  239.                                 client.send_message(saved_message.channel, slotsmsg)
  240.                                
  241.                                 if debugcount == 1:
  242.                                         slotsmsg_win = tagusernoarrow() + "has won slots"
  243.                                
  244.                                         client.send_message(saved_message.channel, slotsmsg_win)
  245.                                        
  246.                                         slots_updatewins(author)
  247.                                
  248.                                 break
  249.                
  250.                         else:
  251.                                 debugcount += 1
  252.                
  253.                 slots_updatetime(author)
  254.                 slots_updatetries(author,debugcount)
  255.                 slots_updateexecutions(author)
  256.                 save_slots()
  257.         elif saved_message.channel.name == bot_channel:
  258.                 client.send_message(saved_message.channel,taguser() + "On cooldown. (%d secs)" % (180 - (time.time() - slots_data[author]["slots_cooldown"])))
  259.  
  260. def cmd_points(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  261.         if not checkForProfile:
  262.                 userNoProfile()
  263.         else:
  264.                 nodecimal_msg = nodecimal(slots_data[author]["slots_points"])
  265.                
  266.                 slots_pointsmsg = taguser() + "Your balance is %s points" % nodecimal_msg
  267.                
  268.                 client.send_message(saved_message.channel, slots_pointsmsg)
  269.        
  270. def cmd_slotsrecords(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  271.         if not checkForProfile():
  272.                 userNoProfile()
  273.         else:
  274.                 slots_recordmsg = taguser() + "Number of !slots done: %s" % (slots_data[author]["slots_executions"])
  275.                
  276.                 client.send_message(saved_message.channel, slots_recordmsg)
  277.                
  278.                 slots_recordmsg = taguser() + "Number of tries: %s" % (slots_data[author]["slots_tries"])
  279.                
  280.                 client.send_message(saved_message.channel, slots_recordmsg)
  281.                
  282.                 slots_recordmsg = taguser() + "Number of wins: %s" % (slots_data[author]["slots_wins"])
  283.                
  284.                 client.send_message(saved_message.channel, slots_recordmsg)
  285.        
  286. def cmd_leaderboards(queries,saved_message,author,taguser,checkForProfile,userNoProfile):
  287.         temp_boards = [(slots_data[username]["slots_points"], username) for username in slots_data]
  288.         temp_boards.sort(key=lambda l: l[0], reverse=True)
  289.        
  290.         boards_message = taguser() + "\r\n%s" % ('\r\n'.join(l[1] + u': ' + unicode(l[0]) for l in temp_boards[:5]))
  291.  
  292.         client.send_message(saved_message.channel, boards_message)
  293.        
  294.  
  295. def get_queries(query,query_types,query_seperator):
  296.         if query_types == "Query":
  297.                 return [query]
  298.         elif not query_types:
  299.                 return [None]
  300.         else:  
  301.                 return (query.split(query_seperator)).append(query)
  302.        
  303.  
  304. bot_channel = "meme-bots"
  305. """
  306. command format:
  307. - command name
  308.         - command function pointer
  309.         - command permissions
  310.         - command channel permissions (None = all channels)
  311.         - command *args
  312.         - command args splitter:
  313.                 - special cases:
  314.                 - None = absolute command
  315.                 -
  316. """
  317.  
  318. commands = {
  319.         "!luckypls":[cmd_luckypls,"Member",None,0,None],
  320.         "!luckyplsperma":[cmd_luckypls,"BotOwner",None,0,None],
  321.         "!luckyplsperma":[cmd_luckypls,"Member",None,0,None],
  322.         "test":[cmd_test,"Member",None,0,""],
  323.         "!yolocoin":[cmd_yolocoin,"Member",bot_channel,0,None],
  324.         "!animation":[cmd_animation,"Member",None,0,None],
  325.         "!scrolltext":[cmd_scrolltext,"Member",None,"Query",None],
  326.         "!wall":[cmd_wall,"Moderators",bot_channel,"Query","-"],
  327.         "!pyramid":[cmd_pyramid,"Moderators",bot_channel,"Query","-"],
  328.         "!funkytext":[cmd_funkytext,"User",None,"Query",None],
  329.         "!enablespam":[cmd_enablespam,"Moderators",None,0,None],
  330.         "!disablespam":[cmd_disablespam,"Moderators",None,0,None],
  331.         "!slots":[cmd_slots,"Member",None,0,None],
  332.         "!records":[cmd_slotsrecords,"Member",bot_channel,0,None],
  333.         "!points":[cmd_points,"Member",bot_channel,0,None],
  334.         "!leaderboards":[cmd_leaderboards,"Member",bot_channel,0,None]
  335. }
  336.  
  337. @client.event
  338. def on_message(message):
  339.         saved_message = message
  340.        
  341.         author = saved_message.author.name
  342.         taguser = lambda: "<@%s> -> " % (saved_message.author.id)
  343.         tagusernoarrow = lambda: "<@%s> " % (saved_message.author.id)
  344.        
  345.         checkForProfile = lambda: True if author in slots_data else False
  346.        
  347.         userNoProfile = lambda: client.send_message(saved_message.channel, taguser() + "You haven't played slots yet.")
  348.        
  349.         if author == "luckytyphlosion" and len(luckymsgs) >= 10:
  350.                 temp_message = luckymsgs.pop(0)
  351.         # commandmanager
  352.         delta_cmd = saved_message.content
  353.         new_cmd = False
  354.         saved_delta_cmd = delta_cmd
  355.        
  356.         for command in commands:
  357.                 possible_cmd = ""
  358.                 delta_cmd = saved_delta_cmd
  359.                 if commands[command][4] == "": # get absolute value
  360.                         if command != delta_cmd:
  361.                                 continue
  362.                         else:
  363.                                 new_cmd = command
  364.                 else:
  365.                         the_cmd = ""
  366.                         if commands[command][4]:
  367.                                 possible_cmd = delta_cmd + commands[command][4]
  368.                                 the_cmd = command + commands[command][4]
  369.                         else:
  370.                                 possible_cmd = delta_cmd.strip()
  371.                                 the_cmd = command.strip()
  372.                        
  373.                         if the_cmd.startswith(possible_cmd):
  374.                                 new_cmd = command
  375.                                 break
  376.                                
  377.         # found a command
  378.         if new_cmd:
  379.                 command = new_cmd
  380.                 # check perms
  381.                 for role in saved_message.author.roles:
  382.                         if author == "luckytyphlosion": # bot owner has access to all commands
  383.                                 pass
  384.                         else:
  385.                                 if not commands[command][1] in role.names:
  386.                                         continue
  387.                                
  388.                                 # check channel perms
  389.                                 if not commands[command][2]:
  390.                                         pass
  391.                                 elif commands[command][2] != saved_message.channel.name:
  392.                                         continue
  393.                        
  394.                         query = (delta_cmd.split(commands[command][4],1)).pop() # get query
  395.                        
  396.                         queries = get_queries(query,commands[command][3],commands[command][4]) # get what type of queries
  397.                        
  398.                         print command
  399.                         commands[command][0](queries,saved_message,author,taguser,checkForProfile,userNoProfile)
  400.                        
  401.                         break
  402.                        
  403.         if author == "luckytyphlosion":
  404.                 luckymsgs.append(saved_message) # do this later so !luckypls doesn't overwrite itself
  405.        
  406. client.run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top