Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. import praw;
  2. import discord;
  3. import config;
  4. from discord.ext import commands;
  5. from discord.ext.commands import Bot;
  6. import sys;
  7. import logging;
  8. import urllib;
  9. import random;
  10. import time;
  11. import asyncio;
  12.  
  13. def login_reddit():
  14.     reddit = praw.Reddit(username = config.rusername,
  15.              password = config.rpassword,
  16.              client_id = config.rclient_id,
  17.              client_secret = config.rclient_secret,
  18.              user_agent = config.ruser_agent);
  19.     print("Successfully logged into Reddit!");
  20.     return reddit;
  21.  
  22. # login to reddit
  23. reddit = login_reddit();
  24.  
  25. def newurl(sb: str, srb: int = None, num: int = None):
  26.     sr = reddit.subreddit(sb).random();
  27.     if srb == True:
  28.         if not sr.is_self:
  29.             slink = sr.url;
  30.             print("Got URL!");
  31.             return slink;
  32.         else:
  33.             print("Isn't a link, running again");
  34.             newurl(sb);
  35.     if sr.over_18:
  36.         if num != None:
  37.             if num > 3:
  38.                 return "I'm sorry, but all posts in the subreddit are NSFW. Please try again.";
  39.                 print("Too many times, stopped!");
  40.             else:
  41.                 ntype = num + 1;
  42.                 print("Post is NSFW! Try: " + str(num));
  43.                 newurl(sb, num = ntype);
  44.         else:
  45.             print("Post is NSFW! Getting another...");
  46.             newurl(sb, num = 1);
  47.     else:
  48.         if not sr.is_self:
  49.             slink = sr.url;
  50.             print("Got URL!");
  51.             return slink;
  52.         else:
  53.             print("Isn't a link, running again");
  54.             newurl(sb);
  55.  
  56. # bot
  57.  
  58. bot = commands.Bot(command_prefix="!$");
  59. @bot.event
  60. async def on_ready():
  61.     print("Bot ready!");
  62. @bot.command()
  63. async def meme(ctx):
  64.     await ctx.send(newurl("meme"));
  65. @bot.command(brief="Gets a nature picture")
  66. async def earth(ctx):
  67.     await ctx.send(newurl(config.esb));
  68. @bot.command(brief="Gets a picture of North Korea")
  69. async def northkorea(ctx):
  70.     await ctx.send(newurl("northkoreapics"));
  71. @bot.command(brief="Returns Gru Memes")
  72. async def grumemes(ctx):
  73.     await ctx.send(newurl("grumemes"));
  74. @bot.command(brief="Gets a link from a specific subreddit", description="Usage: $sub [subreddit]")
  75. async def sub(ctx, *, sbr):
  76.     await ctx.send(newurl(sbr));
  77. @bot.command(brief="Gets search link from the almighty Google", description="Usage: $google [query]")
  78. async def google(ctx, *, query):
  79.     base = "https://google.com/search?q=";
  80.     encode = urllib.parse.quote_plus(query, safe = "", encoding = "utf-8", errors = None);
  81.     await ctx.send(base + encode);
  82.     print("Googled: " + query);
  83. @commands.has_permissions(kick_members = True)
  84. @bot.command(brief="Kicks user. Mod's only", description="Usage: $kick [@user] [reason]")
  85. async def kick(ctx, username: discord.Member, *, kreason = None):
  86.     await discord.Guild.kick(username, reason = kreason);
  87.     await ctx.send("Successfully kicked " + str(username));
  88.     print("Kicked " + str(username));
  89.  
  90. bot.run(config.dtoken);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement