def __init__(self, bot: commands.Bot): self.bot = bot self.ytclient = bot.ytclient self.logchan = bot.logchan self.uclient = UrbanClient() self.animelistsync.start() self.rsscheck.start()
def __init__(self, bot: commands.Bot): self.bot = bot self.logchan = bot.logchan self.uclient = UrbanClient() self.trans = googletrans.Translator() #self.pixapi = pixivpy3.AppPixivAPI() #self.pixapi.login(os.environ['PIXIV_USER'], os.environ['PIXIV_PASS']) self.animelistsync.start() self.rsscheck.start()
def __init__(self, bot): """ Cog initialization Args: bot (discord.ext.commands.Bot): Instance of the bot """ self.bot = bot Config().load_config() self.uClient = UrbanClient()
async def ud(ctx, *, term): clients = UrbanClient() defs = clients.get_definition(term) i = -1 j = -1 temp = 0 try: for d in defs: i += 1 if d.upvotes > temp: j = i temp = d.upvotes i = 0 for d in defs: if i == j: embed = discord.Embed(colour=discord.Colour.green()) embed.set_footer(text=f"{d.upvotes} upvotes") # embed.set_author(name=f"{term}") embed.add_field(name=f"{term.upper()}", value=f"{d.definition}", inline=True) await ctx.send(embed=embed) return i = i + 1 # error handling embed = discord.Embed(colour=discord.Colour.green()) embed.set_footer( text=f"Something went wrong and I am extremely sorry\n┬─┬ ノ( ゜-゜ノ)" ) embed.add_field( name=f"I DON'T F*****G KNOW!", value=f"Go google it yourself you lazy piece of bruh\n(╯°□°)╯︵ ┻━┻", inline=True, ) await ctx.send(embed=embed) except: embed = discord.Embed(colour=discord.Colour.green()) embed.set_footer( text=f"Something went wrong and I am extremely sorry\n┬─┬ ノ( ゜-゜ノ)" ) embed.add_field( name=f"I DON'T F*****G KNOW!", value=f"Go google it yourself you lazy piece of bruh\n(╯°□°)╯︵ ┻━┻", inline=True, ) await ctx.send(embed=embed)
def process(self, user_id: str, payload: Optional[str]) -> None: if not payload: self.__bot_controller.chat('Please provide a search query') return client = UrbanClient() dfns: List[UrbanDefinition] = cast(List[UrbanDefinition], client.get_definition(payload)) if not dfns: self.__bot_controller.chat('No definition found for "%s"' % payload) return dfn = dfns[0] self.__bot_controller.chat([ '%s: %s' % (dfn.word, dfn.definition), '', 'Example:', dfn.example ])
async def urban(ctx, *, arg=None): if arg == None: embederror = discord.Embed() embederror.title = ":x: Invalid argument" embederror.description = "**Todo.urban [search]**" embederror.color = discord.Color.red() return await ctx.send(embed=embederror) try: urban = UrbanClient() defs = urban.get_definition(arg) def0 = defs[0] def1 = defs[1] def2 = defs[2] def3 = defs[3] def4 = defs[4] embeds = [ discord.Embed(title=f"Urban Dictionary - {arg}", description=def0.definition, color=discord.Color.green()), discord.Embed(title=f"Urban Dictionary - {arg}", description=def1.definition, color=discord.Color.green()), discord.Embed(title=f"Urban Dictionary - {arg}", description=def2.definition, color=discord.Color.green()), discord.Embed(title=f"Urban Dictionary - {arg}", description=def3.definition, color=discord.Color.green()), discord.Embed(title=f"Urban Dictionary - {arg}", description=def4.definition, color=discord.Color.green()) ] paginator = BotEmbedPaginator(ctx, embeds) await paginator.run() except Exception: await ctx.send(f"Can't find **{arg}** in Urban Dictionary.")
import discord from discord.ext import commands import asyncio from googlesearch import search import os from random import choice from gtts import gTTS from googletrans import Translator from udpy import UrbanClient import youtube_dl from kiyo import lang from helpy import hell trans = Translator() uclient = UrbanClient() class Utilities(commands.Cog): def __init__(self, bot, ytclient, logchan): self.bot = bot self.ytclient = ytclient self.logchan = logchan @commands.Cog.listener() async def on_message_edit(self, before, after): if before.author.bot or before.content == after.content or before.guild.id != 569845300244774922: return channel = self.bot.get_channel(self.logchan) e = discord.Embed(title=before.author.name, color=0xff0000) e.add_field(name="Edited", value=f'"{before.content}" to "{after.content}"')
class Utilities(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot self.ytclient = bot.ytclient self.logchan = bot.logchan self.uclient = UrbanClient() self.animelistsync.start() self.rsscheck.start() @commands.Cog.listener() async def on_message_edit(self, before: discord.Message, after: discord.Message): if before.author.bot or before.content == after.content or before.guild.id != 569845300244774922: return channel = self.bot.get_channel(self.logchan) e = discord.Embed(title=before.author.name, color=0xff0000) e.add_field(name="Edited", value=f'"{before.content}" to "{after.content}"') await channel.send(embed=e) @commands.Cog.listener() async def on_message(self, message: discord.Message): if message.author.bot or message.content.startswith('?'): return if 'https://www.reddit.com/' in message.content and '/comments/' in message.content: link = '' for word in message.content.split(): if word.startswith('https://www.reddit.com/'): link = word.split('?')[0].strip('/') break resp = requests.get(link+'.json', headers={'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}).json() if resp[0]['data']['children'][0]['data']['over_18'] and not message.channel.is_nsfw(): return e = discord.Embed(title=resp[0]['data']['children'][0]['data']['title'], description=message.content, url=f"https://www.reddit.com{resp[0]['data']['children'][0]['data']['permalink']}") e.add_field(name='Upvotes',value=resp[0]['data']['children'][0]['data']['ups']) e.add_field(name='Author', value=resp[0]['data']['children'][0]['data']['author']) medialink = resp[0]['data']['children'][0]['data']['url_overridden_by_dest'] vlink = None mediameta :dict = resp[0]['data']['children'][0]['data'].get('media_metadata') if medialink.startswith('https://i'): e.set_image(url=medialink) elif medialink.startswith('https://v'): vlink = resp[0]['data']['children'][0]['data']['secure_media']['reddit_video']['fallback_url'] elif mediameta is not None: imgid = choice(list(mediameta)) imgformat = mediameta[imgid]['m'].split('/')[-1] e.set_image(url=f'https://i.redd.it/{imgid}.{imgformat}') e.description+="\n*More images in the link*" hooks = await message.channel.webhooks() if hooks == []: hook = await message.channel.create_webhook(name='generic hook') else: hook = hooks[0] files = list() if message.attachments == []: files = None else: for file in message.attachments: await file.save(file.filename) files.append(discord.File(file.filename)) await hook.send(embed=e, username=message.author.display_name, avatar_url=message.author.avatar_url, files=files) if vlink is not None: await hook.send(content=vlink, username=message.author.display_name, avatar_url=message.author.avatar_url) await message.delete() @tasks.loop(seconds=15.0) async def rsscheck(self): tobefedsoup = requests.get("https://nyaa.si/?page=rss").text feed = bs(tobefedsoup, features="xml") for entry in feed.find_all("item"): for anime in self.animelist: if entry.guid.text == self.guid: return regexshit = re.search(anime.lower().replace(" ", "[\w\s]+"), entry.title.text.lower()) if regexshit is not None and entry.find("nyaa:categoryId").text in ("1_2", "3_1", "4_1"): t = discord.utils.escape_markdown(entry.title.text) e = discord.Embed(title=t, description=entry.find('nyaa:size').text) e.add_field(name="Jump", value=f"[Go to page!]({entry.guid.text})") date = dateparser.parse(entry.pubDate.text) e.timestamp = date e.set_footer(text=entry.find("nyaa:category").text) e.set_author(name="nyaa.si", url="https://nyaa.si") await self.rsschan.send(embed=e) self.guid = feed.find_all("item")[0].guid.text break @rsscheck.before_loop async def beforerss(self): await self.bot.wait_until_ready() self.rsschan: discord.TextChannel = self.bot.get_channel(802132987138801705) self.guid = None @tasks.loop(seconds=60.0) async def animelistsync(self): conn = psycopg2.connect(os.environ['DATABASE_URL']) cur = conn.cursor() cur.execute("SELECT * FROM animelist") self.animelist = [_[0] for _ in cur.fetchall()] @commands.command(aliases=['nword','nw']) async def nwordcount(self, ctx: commands.Context): '''counts your racism''' i=1 n1counter = 0 n2counter = 0 keyword1 = 'NIGGER' keyword2 = 'N***A' mess = "stalking." mes = await ctx.send(content='stalking') while i <5: await mes.edit(content=mess) mess = mess + "." await asyncio.sleep(1) i += 1 async with ctx.channel.typing(): async for message in ctx.channel.history(limit=5000): if message.author.id == ctx.message.author.id: message_text = message.content.upper() if keyword1 in message_text: n1counter += 1 if keyword2 in message_text: n2counter += 1 await mes.edit(content='Done!') await ctx.send(content='According to my stalking, %s have said the soft n-word %d times and the hard n-word %d times in the last 5000 messages' % (ctx.author.mention, n2counter, n1counter)) @commands.command() async def dm(self, ctx: commands.Context, user: discord.User, *, msg: str): '''dms a person i guess''' await ctx.message.delete() await user.send(content=msg) @commands.command() async def say(self, ctx: commands.Context, *, msg: str): '''yes''' await ctx.message.delete() await ctx.send(content=msg, allowed_mentions=discord.AllowedMentions.none()) @commands.command() async def tts(self, ctx: commands.Context, *, msg: str): '''yesser''' msga = await ctx.send(content=msg, tts=True) await msga.delete() await ctx.message.delete() @commands.command() async def calc(self, ctx: commands.Context, *, inp: str): '''It's a calculator''' result = eval(inp) await ctx.send(content=result) @commands.command(aliases=['yt']) async def youtube(self, ctx: commands.Context, *, words: str): '''Searches youtube vids''' results = self.ytclient.search_by_keywords(q=words,search_type='video',limit=1,count=1) link = f'https://youtu.be/{results.items[0].id.videoId}' e = await ctx.send(content=link) @commands.command() async def yeet(self, ctx: commands.Context, *emotes: discord.PartialEmoji): '''Posts the link to a custom emote''' for emote in emotes: await ctx.send(content=emote.url) @commands.command() async def pick(self, ctx: commands.Context, *arg: str): '''Chooses randomly from a list''' await ctx.send(content=choice(arg)) @commands.command() async def mp3(self, ctx: commands.Context, langu: str, *, words: str): '''Generates an mp3 file of whatever you type''' if langu not in lang: words = langu + ' ' + words langu = 'en' tts = gTTS(words, lang=langu) tts.save('kiyo.mp3') await ctx.send(file=discord.File('kiyo.mp3')) @commands.command(aliases=['urbandictionary', 'ud']) async def urban(self, ctx: commands.Context, *, words: str): '''searches the urbandictionary''' try: udthing = self.uclient.get_definition(words)[0] e = discord.Embed(title=udthing.word, description=udthing.definition, color=0x441400) e.add_field(name='Example:', value=udthing.example) await ctx.send(embed=e) except IndexError: await ctx.send(content="Word doesn't exist.") except discord.HTTPException: await ctx.send(content='The definition is a f*****g essay.') @commands.command() async def ytdl(self, ctx: commands.Context, link: str, *, rest: str = None): '''ytdl, but has max limit of 8MB''' if not link.startswith('http'): link = 'ytsearch:' + link + ' ' + rest async with ctx.channel.typing(): with youtube_dl.YoutubeDL({'format': 'mp4', 'outtmpl': 'vid.%(ext)s'}) as ydl: ydl.download([link]) try: await ctx.send(file=discord.File(f'vid.mp4')) except discord.HTTPException: await ctx.send(content="File too large") finally: os.remove(f'vid.mp4') @commands.guild_only() @commands.command() async def clone(self, ctx: commands.Context, user: discord.Member, *, message: str): '''Copies people or sumn idk''' name = user.nick if name is None: name = user.name hook = await ctx.channel.create_webhook(name=name) await hook.send(content=message, username=name, avatar_url=user.avatar_url, allowed_mentions=discord.AllowedMentions(everyone=False, roles=False)) await ctx.message.delete() await hook.delete() @commands.command() async def embed(self, ctx: commands.Context, *, words: str): '''Embeds whatever you say''' e = discord.Embed(title=ctx.author.name, description=words, color=0x523523) e.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url) await ctx.send(embed=e) @commands.command() async def poll(self, ctx: commands.Context, question: str, *choices: str): '''democracy''' if len(choices) > 9: await ctx.send(content="Choices can't be more than 9") return x = 0 e = discord.Embed(title=question, color=0x2f3136) e.set_author(name=f'asked by {ctx.author.display_name}', icon_url=ctx.author.avatar_url) for choice in choices: x = x + 1 e.add_field(name='Choice {}\N{variation selector-16}\N{combining enclosing keycap}'.format(x), value=choice) message = await ctx.send(embed=e) x = 0 for choice in choices: x = x + 1 await message.add_reaction('{}\N{variation selector-16}\N{combining enclosing keycap}'.format(x)) def permcheck(ctx: commands.Context): return ctx.author.id in (230935510439297024, 550076298937237544) @commands.group(invoke_without_command=True) async def rss(self, ctx: commands.Context): '''shows help for rss functions''' if ctx.invoked_subcommand is not None: return await ctx.send_help(ctx.command) @rss.command() @commands.check(permcheck) async def add(self, ctx: commands.Context, *, title: str): '''adds a title to rss nyaa feed''' if title in self.animelist: return await ctx.send(content="Title already tracked") conn = psycopg2.connect(os.environ['DATABASE_URL']) cur = conn.cursor() cur.execute("INSERT INTO animelist(title) VALUES(%s);", (title,)) cur.close() conn.commit() conn.close() await ctx.send(content=f"Added `{title}` into the rss filter\n(Changes may take up to a minute to take place)") @rss.command() @commands.check(permcheck) async def remove(self, ctx: commands.Context, *, title: str): '''removes a title from rss nyaa feed''' conn = psycopg2.connect(os.environ['DATABASE_URL']) cur = conn.cursor() cur.execute("DELETE FROM animelist WHERE title = %s;", (title,)) delrows = cur.rowcount cur.close() conn.commit() conn.close() await ctx.send(content=f"{delrows} deleted entries\n(Changes may take up to a minute to take place)") @rss.command(name="list") async def tracklist(self, ctx: commands.Context): e = discord.Embed(title="nyaa.si rss filter") e.description = "" for i, anime in enumerate(self.animelist): e.description+=f'{i+1}. {anime}\n' await ctx.send(embed=e)
class UrbanDicto(commands.Cog): """ Urban dictionary lookup script. Use with command !ud <word or phrase> """ uClient = None def __init__(self, bot): """ Cog initialization Args: bot (discord.ext.commands.Bot): Instance of the bot """ self.bot = bot Config().load_config() self.uClient = UrbanClient() # Events @commands.Cog.listener() async def on_message(self, message): """on_message executes whenever a message is posted""" if message.content.startswith("!ud"): msg_parts = message.content.split(" ", 1) if len(msg_parts) > 1: await self.lookup_and_send(message.channel, msg_parts[1].strip()) async def lookup_and_send(self, channel, usr_input): defs = self.uClient.get_definition(usr_input) if len(defs) > 0: single_def = None for d in defs: # pick an object that has less than N symbols in text if (len(d.definition) <= 300) and (len(d.example) <= 300): single_def = d break if single_def is not None: single_def.definition = single_def.definition.strip() single_def.definition = re.sub("[\[\]]", "", single_def.definition) single_def.example = single_def.example.strip() single_def.example = re.sub("[\[\]]", "", single_def.example) single_def.example = re.sub("\r\n", "\n", single_def.example) single_def.example = re.sub("\n+", "\n> ", single_def.example) if single_def.example != "": await channel.send( f"**{single_def.word}**:\n{single_def.definition}\n> {single_def.example}\n\n" f":arrow_up:: {single_def.upvotes} :arrow_down:: {single_def.downvotes}" ) else: await channel.send( f"**{single_def.word}**:\n{single_def.definition}\n\n:arrow_up:: {single_def.upvotes}" f" :arrow_down:: {single_def.downvotes}") else: await channel.send("No definition found for **%s**" % (usr_input, )) else: await channel.send("No definition found for **%s**" % (usr_input, ) )
import os import requests import json import asyncio import replit import urbandictionary as ud # urbandictionary repo link: https://github.com/bocong/urbandictionary-py from udpy import UrbanClient from discord.ext import commands from keep_alive import keep_alive # importing keep_alive thread from the script replit.clear() # clear screen client = commands.Bot(command_prefix='.') # bot client, all commands start with '.' uClient = UrbanClient() # UD api wrapper client, https://pypi.org/project/udpy/ token = os.environ['TOKEN'] # do not touch, replit env variable access system. switch = 1 # global variable to control word of the day delay = 7200 # frequency in seconds at which words are posted. @client.command() async def setWoD(ctx, num=1): global switch switch = num @client.command() async def setDelay(ctx, num=3600): global delay
class Utilities(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot self.logchan = bot.logchan self.uclient = UrbanClient() self.trans = googletrans.Translator() #self.pixapi = pixivpy3.AppPixivAPI() #self.pixapi.login(os.environ['PIXIV_USER'], os.environ['PIXIV_PASS']) self.animelistsync.start() self.rsscheck.start() @commands.Cog.listener() async def on_message_edit(self, before: discord.Message, after: discord.Message): if before.author.bot or before.content == after.content or before.guild.id != 569845300244774922: return channel = self.bot.get_channel(self.logchan) e = discord.Embed(title=before.author.name, color=0xff0000) e.add_field(name="Edited", value=f'"{before.content}" to "{after.content}"') await channel.send(embed=e) @commands.Cog.listener() async def on_message(self, message: discord.Message): if message.author.bot or message.content.startswith('?'): return if 'https://www.reddit.com/' in message.content and '/comments/' in message.content: await self.redditConverter(message) #if "https://" in message.content and "pixiv" in message.content and "artworks" in message.content: # await self.pixivConverter(message) async def redditConverter(self, message: discord.Message): link = '' for word in message.content.split(): if word.startswith('https://www.reddit.com/'): link = word.split('?')[0].strip('/') break resp = requests.get(link+'.json', headers={'user-agent': 'kiyohime:kiyo-api:v1.9.0 (by medjed#8988)'}).json() data = resp[0]['data']['children'][0]['data'] if data['over_18'] and not message.channel.is_nsfw(): return e = discord.Embed(title=data['title'], description=message.content, url=f"https://www.reddit.com{data['permalink']}") e.add_field(name='Upvotes',value=data['ups']) e.add_field(name='Author', value=data['author']) medialink = data['url_overridden_by_dest'] vlink = None mediameta :dict = data.get('media_metadata') if medialink.startswith('https://i'): e.set_image(url=medialink) elif medialink.startswith('https://v'): vlink = data['secure_media']['reddit_video']['fallback_url'] elif mediameta is not None: imgid = data['gallery_data']['items'][0]['media_id'] imgformat = mediameta[imgid]['m'].split('/')[-1] e.set_image(url=f'https://i.redd.it/{imgid}.{imgformat}') e.description+="\n*More images in the link*" hooks = await message.channel.webhooks() for hook in hooks: if hook.token: break hook = None if not hook: hook = await message.channel.create_webhook(name='generic hook') files = list() if message.attachments == []: files = None else: for file in message.attachments: await file.save(file.filename) files.append(discord.File(file.filename)) await self.redditSender(hook, e, message.author, message, files, data, vlink) async def redditSender(self, hook: discord.Webhook, embed: discord.Embed, author: discord.Member, message: discord.Message, files: list, reddata: dict = None, video: str = None): hookmsg: discord.WebhookMessage = await hook.send(embed=embed, username=author.display_name, avatar_url=author.avatar_url, files=files, wait=True) def r_check(r, u): return r.message.id == hookmsg.id and not u.bot await hookmsg.add_reaction("🚮") await message.delete() if video: vidmsg = await hook.send(content=video, username=author.display_name, avatar_url=author.avatar_url, wait=True) if reddata.get("media_metadata"): gallery_order = reddata['gallery_data']['items'] metadata = reddata['media_metadata'] await hookmsg.add_reaction("◀") await hookmsg.add_reaction("▶") await hookmsg.add_reaction("❌") embed = hookmsg.embeds[0] embed.set_footer(text=f'1/{len(gallery_order)}') await hookmsg.edit(embed=embed) not_timeout = True while not_timeout: add = self.bot.wait_for('reaction_add', check=r_check) less = self.bot.wait_for('reaction_remove', check=r_check) done, pending = await asyncio.wait([add, less], timeout=600.0, return_when=asyncio.FIRST_COMPLETED) for p in pending: p.cancel() if done: response, user = done.pop().result() if reddata.get("media_metadata"): embed = response.message.embeds[0] image_url: str = embed.image.url image_id = image_url.strip('/').split('/')[-1].split('.')[0] for i, item in enumerate(gallery_order): if image_id == item['media_id']: current_index = i break if response.emoji == "◀" and reddata.get("media_metadata"): i = current_index - 1 if i == -1: i = len(gallery_order) - 1 elif response.emoji == "▶" and reddata.get("media_metadata"): i = current_index + 1 if i == len(metadata): i = 0 elif response.emoji == "🚮" and user.id == author.id: if video: await vidmsg.delete() return await hookmsg.delete() elif response.emoji == "❌" and reddata.get("media_metadata"): break else: continue new_image = gallery_order[i]['media_id'] new_format = metadata[new_image]['m'].split('/')[-1] embed.set_image(url=f'https://i.redd.it/{new_image}.{new_format}') embed.set_footer(text=f'{i+1}/{len(gallery_order)}') await hookmsg.edit(embed=embed) continue else: break await hookmsg.clear_reactions() async def pixivConverter(self, message: discord.Message): art_id = int() for word in message.content.split(): if word.startswith("https://") and "pixiv" in word and "artworks" in word: art_id = int(word.split("/")[-1]) break illu = self.pixapi.illust_detail(art_id) e = discord.Embed(title=illu.title, description=message.content) e.set_author(name=illu['illust']['user']['name']) ext = os.path.splitext(illu['illust']['image_urls']['large'])[1] self.pixapi.download(illu['illust']['image_urls']['large'], name=f"piximg{ext}") e.set_image(url=f"attachment://piximg{ext}") hooks = await message.channel.webhooks() for hook in hooks: if hook.token: break hook = None if not hook: hook = await message.channel.create_webhook(name='generic hook') await hook.send(embed=e, file=discord.File(f"piximg{ext}"), username=message.author.display_name, avatar_url=message.author.avatar_url) files = list() if message.attachments == []: files = None else: for file in message.attachments: await file.save(file.filename) files.append(discord.File(file.filename)) await hook.send(files=files) await message.delete() os.remove(f"piximg{ext}") @tasks.loop(seconds=15.0) async def rsscheck(self): tobefedsoup = requests.get("https://nyaa.si/?page=rss").text feed = bs(tobefedsoup, features="xml") for entry in feed.find_all("item"): for anime in self.animelist: if entry.guid.text == self.guid: return regexshit = re.search(anime.lower().replace(" ", "[\w\s]+"), entry.title.text.lower()) if regexshit is not None and entry.find("nyaa:categoryId").text in ("1_2", "3_1", "4_1"): t = discord.utils.escape_markdown(entry.title.text) e = discord.Embed(title=t, description=entry.find('nyaa:size').text) e.add_field(name="Jump", value=f"[Go to page!]({entry.guid.text})") date = dateparser.parse(entry.pubDate.text) e.timestamp = date e.set_footer(text=entry.find("nyaa:category").text) e.set_author(name="nyaa.si", url="https://nyaa.si") await self.rsschan.send(embed=e) self.guid = feed.find_all("item")[0].guid.text break @rsscheck.before_loop async def beforerss(self): await self.bot.wait_until_ready() self.rsschan: discord.TextChannel = self.bot.get_channel(802132987138801705) self.guid = None @tasks.loop(seconds=60.0) async def animelistsync(self): conn = psycopg2.connect(os.environ['DATABASE_URL']) cur = conn.cursor() cur.execute("SELECT * FROM animelist") self.animelist = [_[0] for _ in cur.fetchall()] cur.close() conn.commit() conn.close() @commands.command(aliases=['nword','nw']) async def nwordcount(self, ctx: commands.Context): '''counts your racism''' i=1 n1counter = 0 n2counter = 0 keyword1 = 'NIGGER' keyword2 = 'N***A' mess = "stalking." mes = await ctx.send(content='stalking') while i <5: await mes.edit(content=mess) mess = mess + "." await asyncio.sleep(1) i += 1 async with ctx.channel.typing(): async for message in ctx.channel.history(limit=5000): if message.author.id == ctx.message.author.id: message_text = message.content.upper() if keyword1 in message_text: n1counter += 1 if keyword2 in message_text: n2counter += 1 await mes.edit(content='Done!') await ctx.send(content='According to my stalking, %s have said the soft n-word %d times and the hard n-word %d times in the last 5000 messages' % (ctx.author.mention, n2counter, n1counter)) @commands.command() async def dm(self, ctx: commands.Context, user: discord.User, *, msg: str): '''dms a person i guess''' await ctx.message.delete() await user.send(content=msg) @commands.command() async def say(self, ctx: commands.Context, *, msg: str): '''yes''' await ctx.message.delete() await ctx.send(content=msg) @commands.command() async def tts(self, ctx: commands.Context, *, msg: str): '''yesser''' msga = await ctx.send(content=msg, tts=True) await msga.delete() await ctx.message.delete() @commands.command() async def calc(self, ctx: commands.Context, *, inp: str): '''It's a calculator''' await self.bot.get_cog('Google').calculate(ctx=ctx, query=inp) @commands.command(aliases=['yt']) async def youtube(self, ctx: commands.Context = None, *, words: str): '''Searches youtube vids''' with youtube_dl.YoutubeDL() as ydl: results = ydl.extract_info(f'ytsearch: {words}', download=False) link = f'https://youtu.be/{results["entries"][0]["id"]}' if ctx == None: return link e = await ctx.send(content=link) @commands.command() async def yeet(self, ctx: commands.Context, *emotes: discord.PartialEmoji): '''Posts the link to a custom emote''' for emote in emotes: await ctx.send(content=emote.url) @commands.command() async def pick(self, ctx: commands.Context, *arg: str): '''Chooses randomly from a list''' await ctx.send(content=choice(arg)) @commands.command() async def mp3(self, ctx: commands.Context, langu: str, *, words: str): '''Generates an mp3 file of whatever you type''' if langu not in lang: words = langu + ' ' + words langu = 'en' tts = gTTS(words, lang=langu) tts.save('kiyo.mp3') await ctx.send(file=discord.File('kiyo.mp3')) @commands.command(aliases=['urbandictionary', 'ud']) async def urban(self, ctx: commands.Context, *, words: str): '''searches the urbandictionary''' try: udthing = self.uclient.get_definition(words)[0] e = discord.Embed(title=udthing.word, description=udthing.definition, color=0x441400) e.add_field(name='Example:', value=udthing.example) await ctx.send(embed=e) except IndexError: await ctx.send(content="Word doesn't exist.") except discord.HTTPException: await ctx.send(content='The definition is a f*****g essay.') @commands.command() async def ytdl(self, ctx: commands.Context, link: str, *, rest: str = ''): '''ytdl, but has max limit of 8MB''' if not link.startswith('http') and not link.startswith('<'): link = 'ytsearch:' + link + ' ' + rest elif link.startswith('<http') and link.endswith('>'): link = link.strip('<>') async with ctx.channel.typing(): with youtube_dl.YoutubeDL({'format': 'mp4', 'outtmpl': 'vid.mp4'}) as ydl: ydl.download([link]) try: await ctx.send(file=discord.File('vid.mp4')) except discord.HTTPException: if link.startswith('ytsearch:'): with youtube_dl.YoutubeDL() as ydl: results = ydl.extract_info(link, download=False) link = f'https://youtu.be/{results["entries"][0]["id"]}' await ctx.send(content=f"File too large, download from https://kiyo-api.herokuapp.com/ytdl?link={quote(link)} instead") os.remove('vid.mp4') @commands.guild_only() @commands.command() async def clone(self, ctx: commands.Context, user: discord.Member, *, message: str = None): '''Copies people or sumn idk''' name = user.nick if name is None: name = user.name files = list() if ctx.message.attachments: for att in ctx.message.attachments: await att.save(att.filename) files.append(discord.File(att.filename)) else: files = None if ctx.message.reference: quote: discord.Message = ctx.message.reference.resolved q_author = quote.author q_content = quote.content.splitlines() new_q = list() for line in q_content: new_q.append(f"> {line}") new_q = '\n'.join(new_q) message = f"{new_q}\n{message}" if q_author in ctx.message.mentions: message = f"{q_author.mention}\n{message}" hooks = await ctx.channel.webhooks() for hook in hooks: if hook.token: break hook = None if not hook: hook = await message.channel.create_webhook(name='generic hook') try: await hook.send(content=message, username=name, avatar_url=user.avatar_url, files=files) except discord.HTTPException: await ctx.send(content="you have to set either files or message to send") await ctx.message.delete() @commands.command() async def embed(self, ctx: commands.Context, *, words: str): '''Embeds whatever you say''' e = discord.Embed(title=ctx.author.name, description=words, color=0x523523) e.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url) msg: discord.Message = await ctx.send(embed=e) await msg.add_reaction('🚮') def check(reaction, user): return reaction.emoji == '🚮' and user == ctx.author try: await self.bot.wait_for('reaction_add', check=check, timeout=600.0) await msg.delete() except asyncio.TimeoutError: await msg.clear_reactions() @commands.command() async def poll(self, ctx: commands.Context, question: str, *choices: str): '''democracy''' if len(choices) > 9: await ctx.send(content="Choices can't be more than 9") return x = 0 e = discord.Embed(title=question, color=0x2f3136) e.set_author(name=f'asked by {ctx.author.display_name}', icon_url=ctx.author.avatar_url) for choice in choices: x = x + 1 e.add_field(name='Choice {}\N{variation selector-16}\N{combining enclosing keycap}'.format(x), value=choice) message = await ctx.send(embed=e) x = 0 for choice in choices: x = x + 1 await message.add_reaction('{}\N{variation selector-16}\N{combining enclosing keycap}'.format(x)) await message.add_reaction('🚮') def check(reaction, user): return reaction.emoji == '🚮' and user == ctx.author try: await self.bot.wait_for('reaction_add', check=check, timeout=600.0) await message.delete() except asyncio.TimeoutError: await message.clear_reactions() def permcheck(ctx: commands.Context): return ctx.author.id in (230935510439297024, 550076298937237544) @commands.group(invoke_without_command=True) async def rss(self, ctx: commands.Context): '''shows help for rss functions''' if ctx.invoked_subcommand is not None: return await ctx.send_help(ctx.command) @rss.command() @commands.check(permcheck) async def add(self, ctx: commands.Context, *, title: str): '''adds a title to rss nyaa feed''' if title in self.animelist: return await ctx.send(content="Title already tracked") conn = psycopg2.connect(os.environ['DATABASE_URL']) cur = conn.cursor() cur.execute("INSERT INTO animelist(title) VALUES(%s);", (title,)) cur.close() conn.commit() conn.close() await ctx.send(content=f"Added `{title}` into the rss filter\n(Changes may take up to a minute to take place)") @rss.command() @commands.check(permcheck) async def remove(self, ctx: commands.Context, *, title: str): '''removes a title from rss nyaa feed''' conn = psycopg2.connect(os.environ['DATABASE_URL']) cur = conn.cursor() cur.execute("DELETE FROM animelist WHERE title = %s;", (title,)) delrows = cur.rowcount cur.close() conn.commit() conn.close() await ctx.send(content=f"{delrows} deleted entries\n(Changes may take up to a minute to take place)") @rss.command(name="list") async def tracklist(self, ctx: commands.Context): e = discord.Embed(title="nyaa.si rss filter") e.description = "" for i, anime in enumerate(self.animelist): e.description+=f'{i+1}. {anime}\n' await ctx.send(embed=e) @commands.command(aliases=['trans']) async def translate(self, ctx: commands.Context, query: str, destination: str = 'en', source: str = 'auto'): try: res = self.trans.translate(query, destination, source) except ValueError: langlist = "\n".join(lang) return await ctx.send(content=f'Language choice must be one of these:\n```\n{langlist}```') e = discord.Embed(title="Translator", color=0x36393F) e.add_field(name=f"Translated from {res.src} to {res.dest}", value=res.text) await ctx.send(embed=e) @commands.command(hidden=True) async def clean(self, ctx: commands.Context, amount: int = 10): def is_me(m: discord.Message): return m.author == self.bot.user delmsglist = await ctx.channel.purge(limit=amount, check=is_me, bulk=False) delmsg: discord.Message = await ctx.send(content=f'Deleted {len(delmsglist)} responses(s)') await delmsg.delete(delay=5) @commands.command() async def click(self, ctx: commands.Context, link: str): '''saves you a click''' header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'} async with aiohttp.ClientSession() as sess: async with sess.get(link, headers=header) as req: r = await req.text() soup = bs(r, 'html.parser') text = str() for p in soup.find('div').find_all('p'): text += p.text + '\n' with open('clicked.txt', 'w', encoding='utf-8') as f: f.write(text) await ctx.send(file=discord.File('clicked.txt'))