您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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)
  122. async def emote(self, ctx, emote):
  123. """
  124. Gets a url to the emote given. Useful for downloading emotes.
  125. """
  126. emoteid = emote.split(":")[-1].strip("<>")
  127. url = "https://discordapp.com/api/emojis/{}.png".format(emoteid)
  128. return await self.bot.say(url)
  129. @bot.command(pass_context=True, hidden=True)
  130. @checks.is_bot_owner()
  131. async def echo(self, ctx, channel, *, message: str):
  132. if ctx.message.channel_mentions:
  133. for channel in ctx.message.channel_mentions:
  134. await self.bot.send_message(channel, content=message)
  135. return await self.bot.say(":point_left:")
  136. elif channel.isdigit():
  137. channel = ctx.message.server.get_channel(channel)
  138. await self.bot.send_message(channel, content=message)
  139. return await self.bot.say(":point_left:")
  140. else:
  141. return await self.bot.say("You did something wrong smh")
  142. def setup(Bot):
  143. Bot.add_cog(Util(Bot))