You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.9KB

  1. import os
  2. import json
  3. import checks
  4. import random
  5. import aiohttp
  6. import discord
  7. import requests
  8. from discord.ext.commands import bot
  9. class Util():
  10. """
  11. A cog that offers utility commands.
  12. """
  13. def __init__(self, Bot):
  14. self.bot = Bot
  15. @bot.command(pass_context=True)
  16. async def avatar(self, ctx, *,user: discord.User = None):
  17. """
  18. Returns a mentioned users avatar
  19. Example:
  20. {command_prefix}avatar @RoxBot#4170
  21. {command_prefix}avatar RoxBot
  22. """
  23. if not user:
  24. user = ctx.message.author
  25. url = user.avatar_url
  26. avaimg = 'avaimg.webp'
  27. async with aiohttp.ClientSession() as session:
  28. async with session.get(url) as img:
  29. with open(avaimg, 'wb') as f:
  30. f.write(await img.read())
  31. await self.bot.send_file(ctx.message.channel, avaimg)
  32. os.remove(avaimg)
  33. @bot.command(pass_context=True)
  34. async def info(self, ctx, member: discord.Member = None):
  35. """
  36. Gets info for a mentioned user
  37. Example:
  38. {command_prefix}info @RoxBot#4170
  39. {command_prefix}info RoxBot
  40. """
  41. if not member:
  42. member = ctx.message.author
  43. name_disc = member.name + "#" + member.discriminator
  44. if member.game:
  45. if member.game.type:
  46. game = "**" + member.game.name + "**"
  47. desc = "Streaming "
  48. else:
  49. game = "**" + member.game.name + "**"
  50. desc = "Playing "
  51. else:
  52. desc = ""
  53. game = ""
  54. colour = member.colour.value
  55. avatar = member.avatar_url
  56. embed = discord.Embed(colour=colour, description=desc+game)
  57. embed.set_thumbnail(url=avatar)
  58. embed.set_author(name=name_disc, icon_url=avatar)
  59. embed.add_field(name="ID", value=member.id)
  60. embed.add_field(name="Status", value=member.status)
  61. if member.nick:
  62. embed.add_field(name="Nickname", value=member.nick)
  63. embed.add_field(name="Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at), inline=True)
  64. embed.add_field(name="Joined Server", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.joined_at), inline=True)
  65. roles = ""
  66. count = 0
  67. for role in member.roles:
  68. if role == ctx.message.server.default_role:
  69. pass
  70. else:
  71. roles += role.name + ", "
  72. count += 1
  73. embed.add_field(name="Roles [{}]".format(count), value=roles.strip(", "))
  74. return await self.bot.say(embed=embed)
  75. @bot.command(pass_context=True)
  76. async def upload(self, ctx):
  77. """
  78. Uploads selected file to the host, thanks to the fact that
  79. every pomf.se based site has pretty much the same architecture.
  80. """
  81. sites = [
  82. "https://comfy.moe/",
  83. "https://safe.moe/api/",
  84. "http://up.che.moe/",
  85. "https://mixtape.moe/",
  86. "https://pomf.cat/",
  87. "https://sugoi.vidyagam.es/",
  88. "https://doko.moe/",
  89. "https://pomfe.co/",
  90. "https://pomf.space/",
  91. "https://vidga.me/",
  92. "https://pomf.pyonpyon.moe/"
  93. ] # List of pomf clone sites and upload limits
  94. await self.bot.send_typing(ctx.message.channel)
  95. if ctx.message.attachments:
  96. # Site choice, shouldn't need an upload size check since max upload for discord atm is 50MB
  97. site = random.choice(sites)
  98. urls = []
  99. for attachment in ctx.message.attachments:
  100. name = attachment['url'].split("/")[-1]
  101. # Download File
  102. with aiohttp.ClientSession() as session:
  103. async with session.get(attachment['url']) as img:
  104. with open(name, 'wb') as f:
  105. f.write(await img.read())
  106. # Upload file
  107. try:
  108. with open(name, 'rb') as f:
  109. answer = requests.post(url=site+"upload.php",files={'files[]': f.read()})
  110. response = json.loads(answer.text)
  111. file_name_1 = response["files"][0]["url"].replace("\\", "")
  112. urls.append(file_name_1)
  113. except Exception as e:
  114. print(e)
  115. print(name + ' couldn\'t be uploaded to ' + site)
  116. os.remove(name)
  117. msg = "".join(urls)
  118. return await self.bot.say(msg)
  119. else:
  120. return await self.bot.say("Send me shit to upload nig")
  121. @bot.command(pass_context=True, aliases=["emoji"]) # This command will only work with normal emoji once I can put in something to get the svgs for twiemoji and convert em
  122. async def emote(self, ctx, emote):
  123. """
  124. Uploads the emote given. Useful for downloading emotes. ONLY WORKS WITH CUSTOM EMOJI
  125. """
  126. emoteid = emote.split(":")[-1].strip("<>")
  127. if not emoteid.isdigit():
  128. return await self.bot.say("This command only works with custom emotes.")
  129. url = "https://discordapp.com/api/emojis/{}.png".format(emoteid)
  130. imgname = 'img.png'
  131. async with aiohttp.ClientSession() as session:
  132. async with session.get(url) as img:
  133. with open(imgname, 'wb') as f:
  134. f.write(await img.read())
  135. await self.bot.send_file(ctx.message.channel, imgname)
  136. os.remove(imgname)
  137. #return await self.bot.say(url)
  138. @bot.command(pass_context=True, enabled=False, hidden=True)
  139. @checks.is_bot_owner()
  140. async def emoterob(self, ctx, emote, name=None):
  141. """
  142. Gets a emoji and adds it to the custom emoji list. ONLY WORKS WITH CUSTOM EMOJI
  143. """
  144. emoteid = emote.split(":")[-1].strip("<>")
  145. if not emoteid.isdigit():
  146. return await self.bot.say("This command only works with custom emotes.")
  147. url = "https://discordapp.com/api/emojis/{}.png".format(emoteid)
  148. imgname = 'img.png'
  149. async with aiohttp.ClientSession() as session:
  150. async with session.get(url) as img:
  151. with open(imgname, 'wb') as f:
  152. f.write(await img.read())
  153. with open(imgname, "rb") as f:
  154. return await self.bot.create_custom_emoji(ctx.message.server, name=name, image=f)
  155. @bot.command(pass_context=True, hidden=True)
  156. @checks.is_bot_owner()
  157. async def echo(self, ctx, channel, *, message: str):
  158. if ctx.message.channel_mentions:
  159. for channel in ctx.message.channel_mentions:
  160. await self.bot.send_message(channel, content=message)
  161. return await self.bot.say(":point_left:")
  162. elif channel.isdigit():
  163. channel = ctx.message.server.get_channel(channel)
  164. await self.bot.send_message(channel, content=message)
  165. return await self.bot.say(":point_left:")
  166. else:
  167. return await self.bot.say("You did something wrong smh")
  168. @bot.command(pass_context=True, enabled=False, hidden=True)
  169. async def say(self, ctx, *, echo):
  170. return await self.bot.say(echo)
  171. def setup(Bot):
  172. Bot.add_cog(Util(Bot))