Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw;
- import discord;
- import config;
- from discord.ext import commands;
- from discord.ext.commands import Bot;
- import sys;
- import logging;
- import urllib;
- import random;
- import time;
- import asyncio;
- def login_reddit():
- reddit = praw.Reddit(username = config.rusername,
- password = config.rpassword,
- client_id = config.rclient_id,
- client_secret = config.rclient_secret,
- user_agent = config.ruser_agent);
- print("Successfully logged into Reddit!");
- return reddit;
- # login to reddit
- reddit = login_reddit();
- def newurl(sb: str, srb: int = None, num: int = None):
- sr = reddit.subreddit(sb).random();
- if srb == True:
- if not sr.is_self:
- slink = sr.url;
- print("Got URL!");
- return slink;
- else:
- print("Isn't a link, running again");
- newurl(sb);
- if sr.over_18:
- if num != None:
- if num > 3:
- return "I'm sorry, but all posts in the subreddit are NSFW. Please try again.";
- print("Too many times, stopped!");
- else:
- ntype = num + 1;
- print("Post is NSFW! Try: " + str(num));
- newurl(sb, num = ntype);
- else:
- print("Post is NSFW! Getting another...");
- newurl(sb, num = 1);
- else:
- if not sr.is_self:
- slink = sr.url;
- print("Got URL!");
- return slink;
- else:
- print("Isn't a link, running again");
- newurl(sb);
- # bot
- bot = commands.Bot(command_prefix="!$");
- @bot.event
- async def on_ready():
- print("Bot ready!");
- @bot.command()
- async def meme(ctx):
- await ctx.send(newurl("meme"));
- @bot.command(brief="Gets a nature picture")
- async def earth(ctx):
- await ctx.send(newurl(config.esb));
- @bot.command(brief="Gets a picture of North Korea")
- async def northkorea(ctx):
- await ctx.send(newurl("northkoreapics"));
- @bot.command(brief="Returns Gru Memes")
- async def grumemes(ctx):
- await ctx.send(newurl("grumemes"));
- @bot.command(brief="Gets a link from a specific subreddit", description="Usage: $sub [subreddit]")
- async def sub(ctx, *, sbr):
- await ctx.send(newurl(sbr));
- @bot.command(brief="Gets search link from the almighty Google", description="Usage: $google [query]")
- async def google(ctx, *, query):
- base = "https://google.com/search?q=";
- encode = urllib.parse.quote_plus(query, safe = "", encoding = "utf-8", errors = None);
- await ctx.send(base + encode);
- print("Googled: " + query);
- @commands.has_permissions(kick_members = True)
- @bot.command(brief="Kicks user. Mod's only", description="Usage: $kick [@user] [reason]")
- async def kick(ctx, username: discord.Member, *, kreason = None):
- await discord.Guild.kick(username, reason = kreason);
- await ctx.send("Successfully kicked " + str(username));
- print("Kicked " + str(username));
- bot.run(config.dtoken);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement