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.

util.py 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 ctx.message.mentions:
  24. user = ctx.message.mentions[0]
  25. elif not user:
  26. user = ctx.message.author
  27. url = user.avatar_url
  28. avaimg = 'avaimg.webp'
  29. async with aiohttp.ClientSession() as session:
  30. async with session.get(url) as img:
  31. with open(avaimg, 'wb') as f:
  32. f.write(await img.read())
  33. await self.bot.send_file(ctx.message.channel, avaimg)
  34. os.remove(avaimg)
  35. @bot.command(pass_context=True)
  36. async def info(self, ctx, member: discord.Member = None):
  37. """
  38. Gets info for a mentioned user
  39. Example:
  40. {command_prefix}info @RoxBot#4170
  41. {command_prefix}info RoxBot
  42. """
  43. if not member:
  44. member = ctx.message.author
  45. name_disc = member.name + "#" + member.discriminator
  46. if member.game:
  47. if member.game.type:
  48. game = "**" + member.game.name + "**"
  49. desc = "Streaming "
  50. else:
  51. game = "**" + member.game.name + "**"
  52. desc = "Playing "
  53. else:
  54. desc = ""
  55. game = ""
  56. colour = member.colour.value
  57. avatar = member.avatar_url
  58. embed = discord.Embed(colour=colour, description=desc+game)
  59. embed.set_thumbnail(url=avatar)
  60. embed.set_author(name=name_disc, icon_url=avatar)
  61. embed.add_field(name="ID", value=member.id)
  62. embed.add_field(name="Status", value=member.status)
  63. if member.nick:
  64. embed.add_field(name="Nickname", value=member.nick)
  65. embed.add_field(name="Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at), inline=True)
  66. embed.add_field(name="Joined Server", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.joined_at), inline=True)
  67. roles = ""
  68. count = 0
  69. for role in member.roles:
  70. if role == ctx.message.server.default_role:
  71. pass
  72. else:
  73. roles += role.name + ", "
  74. count += 1
  75. embed.add_field(name="Roles [{}]".format(count), value=roles.strip(", "))
  76. return await self.bot.say(embed=embed)
  77. @bot.command(pass_context=True)
  78. async def upload(self, ctx):
  79. """
  80. Uploads selected file to the host, thanks to the fact that
  81. every pomf.se based site has pretty much the same architecture.
  82. """
  83. sites = [
  84. "https://comfy.moe/",
  85. "https://safe.moe/api/",
  86. "http://up.che.moe/",
  87. "https://mixtape.moe/",
  88. "https://pomf.cat/",
  89. "https://sugoi.vidyagam.es/",
  90. "https://doko.moe/",
  91. "https://pomfe.co/",
  92. "https://pomf.space/",
  93. "https://vidga.me/",
  94. "https://pomf.pyonpyon.moe/"
  95. ] # List of pomf clone sites and upload limits
  96. await self.bot.send_typing(ctx.message.channel)
  97. if ctx.message.attachments:
  98. # Site choice, shouldn't need an upload size check since max upload for discord atm is 50MB
  99. site = random.choice(sites)
  100. urls = []
  101. for attachment in ctx.message.attachments:
  102. name = attachment['url'].split("/")[-1]
  103. # Download File
  104. with aiohttp.ClientSession() as session:
  105. async with session.get(attachment['url']) as img:
  106. with open(name, 'wb') as f:
  107. f.write(await img.read())
  108. # Upload file
  109. try:
  110. with open(name, 'rb') as f:
  111. answer = requests.post(url=site+"upload.php",files={'files[]': f.read()})
  112. response = json.loads(answer.text)
  113. file_name_1 = response["files"][0]["url"].replace("\\", "")
  114. urls.append(file_name_1)
  115. except Exception as e:
  116. print(e)
  117. print(name + ' couldn\'t be uploaded to ' + site)
  118. os.remove(name)
  119. msg = "".join(urls)
  120. return await self.bot.say(msg)
  121. else:
  122. return await self.bot.say("Send me shit to upload nig")
  123. @bot.command(pass_context=True)
  124. async def emote(self, ctx, emote):
  125. emoteid = emote.split(":")[-1].strip("<>")
  126. url = "https://discordapp.com/api/emojis/{}.png".format(emoteid)
  127. return await self.bot.say(url)
  128. @bot.command(pass_context=True, hidden=True)
  129. @checks.is_bot_owner()
  130. async def echo(self, ctx, channel, *, message: str):
  131. if ctx.message.channel_mentions:
  132. for channel in ctx.message.channel_mentions:
  133. await self.bot.send_message(channel, content=message)
  134. return await self.bot.say(":point_left:")
  135. elif channel.isdigit():
  136. channel = ctx.message.server.get_channel(channel)
  137. await self.bot.send_message(channel, content=message)
  138. return await self.bot.say(":point_left:")
  139. else:
  140. return await self.bot.say("You did something wrong smh")
  141. def setup(Bot):
  142. Bot.add_cog(Util(Bot))