Parcourir la source

added util and the upload command to it. Also edited some other bits. Added a nsfw setting for the nsfw cog later.

tags/v1.0.0
roxie il y a 6 ans
Parent
révision
e8871e510a
6 fichiers modifiés avec 147 ajouts et 7 suppressions
  1. +2
    -2
      cogs/selfassign.py
  2. +139
    -0
      cogs/util.py
  3. +2
    -1
      config/cogs.py
  4. +3
    -0
      config/server_config.py
  5. +1
    -1
      config/servers.json
  6. +0
    -3
      main.py

+ 2
- 2
cogs/selfassign.py Voir le fichier

roles = '\n'.join(roles) roles = '\n'.join(roles)
embed = discord.Embed(colour=discord.Colour(0xDEADBF), # Make Embed colour a constant embed = discord.Embed(colour=discord.Colour(0xDEADBF), # Make Embed colour a constant
description="The self-assignable roles for this server are: \n"+roles) description="The self-assignable roles for this server are: \n"+roles)
return await self.bot.send_message(ctx.message.channel, embed=embed)
return await self.bot.say(embed=embed)


@commands.command(pass_context=True) @commands.command(pass_context=True)
async def iam(self, ctx, role: discord.Role = None): async def iam(self, ctx, role: discord.Role = None):
""" """
Self-assign yourself a role. Only one role at a time. Doesn't work for roles with spaces.
Self-assign yourself a role. Only one role at a time.
Usage: Usage:
{command_prefix}iam [role] {command_prefix}iam [role]
Example: Example:

+ 139
- 0
cogs/util.py Voir le fichier

import os
import json
import random
import aiohttp
import discord
import requests
from discord.ext.commands import bot

class Util():
"""
A cog that offers utility commands.
"""
def __init__(self, Bot):
self.bot = Bot

@bot.command(pass_context=True)
async def avatar(self, ctx, user: discord.User = None):
"""
Returns a mentioned users avatar
Example:
{command_prefix}avatar @RoxBot#4170
{command_prefix}avatar RoxBot
"""
if ctx.message.mentions:
user = ctx.message.mentions[0]
elif not user:
user = ctx.message.author

url = user.avatar_url
avaimg = 'avaimg.webp'

async with aiohttp.ClientSession() as session:
async with session.get(url) as img:
with open(avaimg, 'wb') as f:
f.write(await img.read())
await self.bot.send_file(ctx.message.channel, avaimg)
os.remove(avaimg)


@bot.command(pass_context=True)
async def info(self, ctx, member: discord.Member = None):
"""
Gets info for a mentioned user
Example:
{command_prefix}info @RoxBot#4170
{command_prefix}info RoxBot
"""
if not member:
member = ctx.message.author
name_disc = member.name + "#" + member.discriminator
if member.game:
if member.game.type:
game = "**" + member.game.name + "**"
desc = "Streaming "
else:
game = "**" + member.game.name + "**"
desc = "Playing "
else:
desc = ""
game = ""

colour = member.colour.value
avatar = member.avatar_url

embed = discord.Embed(colour=colour, description=desc+game)
embed.set_thumbnail(url=avatar)
embed.set_author(name=name_disc, icon_url=avatar)

embed.add_field(name="ID", value=member.id)
embed.add_field(name="Status", value=member.status)
if member.nick:
embed.add_field(name="Nickname", value=member.nick)
embed.add_field(name="Account Created", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.created_at), inline=True)
embed.add_field(name="Joined Server", value="{:%a %Y/%m/%d %H:%M:%S} UTC".format(member.joined_at), inline=True)

roles = ""
count = 0

for role in member.roles:
if role == ctx.message.server.default_role:
pass
else:
roles += role.name + ", "
count += 1
embed.add_field(name="Roles [{}]".format(count), value=roles.strip(", "))
return await self.bot.say(embed=embed)


@bot.command(pass_context=True)
async def upload(self, ctx):
"""
Uploads selected file to the host, thanks to the fact that
every pomf.se based site has pretty much the same architecture.
"""
sites = [
"https://comfy.moe/",
"https://safe.moe/api/",
"http://up.che.moe/",
"https://mixtape.moe/",
"https://pomf.cat/",
"https://sugoi.vidyagam.es/",
"https://doko.moe/",
"https://pomfe.co/",
"https://pomf.space/",
"https://vidga.me/",
"https://pomf.pyonpyon.moe/"
] # List of pomf clone sites and upload limits

await self.bot.send_typing(ctx.message.channel)
if ctx.message.attachments:
# Site choice, shouldn't need an upload size check since max upload for discord atm is 50MB
site = random.choice(sites)
urls = []
for attachment in ctx.message.attachments:
name = attachment['url'].split("/")[-1]
# Download File
with aiohttp.ClientSession() as session:
async with session.get(attachment['url']) as img:
with open(name, 'wb') as f:
f.write(await img.read())
# Upload file
try:
with open(name, 'rb') as f:
answer = requests.post(url=site+"upload.php",files={'files[]': f.read()})
response = json.loads(answer.text)
file_name_1 = response["files"][0]["url"].replace("\\", "")
urls.append(file_name_1)
except Exception as e:
print(e)
print(name + ' couldn\'t be uploaded to ' + site)
os.remove(name)
msg = "".join(urls)
return await self.bot.say(msg)
else:
return await self.bot.say("Send me shit to upload nig")


def setup(Bot):
Bot.add_cog(Util(Bot))

+ 2
- 1
config/cogs.py Voir le fichier

cogs = [ cogs = [
"cogs.selfassign", "cogs.selfassign",
"cogs.joinleave", "cogs.joinleave",
"cogs.settings"
"cogs.settings",
"cogs.util"
] ]

+ 3
- 0
config/server_config.py Voir le fichier

"mute": { "mute": {
"role": "", "role": "",
"admin-role": [] "admin-role": []
},
"nsfw": {
"enabled": 0
} }
} }
} }

+ 1
- 1
config/servers.json Voir le fichier

{"304048071963312130": {"greets": {"enabled": 1, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": ["307330606348632064", "308081570059649024", "308081662787321861"]}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}}}
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0}}}

+ 0
- 3
main.py Voir le fichier

# TODO: Check for words for reactions and check blacklist # TODO: Check for words for reactions and check blacklist
if blacklisted(message.author): if blacklisted(message.author):
return return

return await bot.process_commands(message) return await bot.process_commands(message)


# Bot Debug and Info # Bot Debug and Info
await bot.send_message(bot.owner, embed=embed) await bot.send_message(bot.owner, embed=embed)
except: except:
pass pass
else:
raise error




if not os.path.isfile("settings/preferences.ini"): if not os.path.isfile("settings/preferences.ini"):

Chargement…
Annuler
Enregistrer