Exemplo n.º 1
0
    async def reload_data(self, filename, key=None):
        if not key:
            head, key = os.path.split(filename)
            key = key[:key.find(".")]

        if os.path.exists(filename):
            data = rockutils.load_json(filename)
            if not key:
                head, key = os.path.split(filename)
                key = key[:key.find(".")]
            setattr(self.bot, key, data)
            return True, key
        else:
            return False, key
Exemplo n.º 2
0
    async def get_user_info(self, user_id, refer=""):
        rockutils.pprint(
            f"{f'[Refer: {refer}] ' if refer != '' else ''}Getting information for {user_id}",
            prefix="get_user_info",
            prefix_colour="light green")
        user_data = await r.table("users").get(int(user_id)
                                               ).run(self.bot.connection)

        update = False
        new = False

        user = self.bot.get_user(self, int(user_id))

        if user_data is None and user:
            user_data = copy.deepcopy(
                rockutils.load_json("data/default_user.json"))
            user_data['id'] = int(user_id)
            user_data['details']['user_addition'] = math.ceil(time.time())
            user_data['previous_names'].append(
                [user.name, math.ceil(time.time())])
            new = True

        if user:
            if not self.bot.cluster_id in user_data['last_mutual']:
                user_data['last_mutual'][self.bot.cluster_id] = 0
                update = True
            if time.time() - user_data['last_mutual'][
                    self.bot.cluster_id] > 600:
                user_data['mutual'][self.bot.cluster_id] = self.mutual_guilds(
                    self, user)
                user_data['last_mutual'][self.bot.cluster_id] = time.time()
                update = True

            if time.time() - user_data['details'] > 600:
                user_data['details']['avatar'] = [
                    user.avatar_url_as(format="jpeg", size=64),
                    user.avatar_url_as(format="png", size=256)
                ]
                if user.name != user_data['details']['name']:
                    user_data['previous_names'].append(
                        [user.name, math.ceil(time.time())])
                user_data['details']['name'] = user.name
                user_data['details']['discriminator'] = user.discriminator
                user_data['details']['user_creation'] = math.ceil(
                    user.created_at.timestamp())
                user_data['details']['update'] = time.time()
                update = True

        if update or new:
            if new:
                rockutils.pprint(f"Creating information for {user_id}",
                                 prefix="get_user_info",
                                 prefix_colour="light green")
                await r.table("users").insert(user_data).run(
                    self.bot.connection)
            else:
                await update_user_info(self,
                                       user_id,
                                       user_data,
                                       refer="get_user_info")

        return user_data
Exemplo n.º 3
0
    async def get_guild_info(self, guild_id, refer=""):
        rockutils.pprint(
            f"{f'[Refer: {refer}] ' if refer != '' else ''}Getting information for {guild_id}",
            prefix="get_guild_info",
            prefix_colour="light green")
        guild_data = await r.table("guilds").get(int(guild_id)
                                                 ).run(self.bot.connection)

        update = False
        new = False

        guild = self.bot.get_guild(self, int(guild_id))

        if guild_data is None and guild:
            guild_data = copy.deepcopy(
                rockutils.load_json("data/default_guild.json"))
            guild_data['id'] = int(guild_id)
            guild_data['details']['guild_addition'] = math.ceil(time.time())
            mew = True

        guild_data['cluster'] = self.bot.cluster_id

        if guild:
            if time.time() - guild_data['details']['update'] > 600:
                guild_data['details']['splash'] = guild.splash
                guild_data['details']['region'] = str(guild.region)
                guild_data['details']['icon'] = [
                    guild.icon_url_as(format="jpeg", size=64),
                    guild.icon_url_as(format="png", size=256)
                ]
                guild_data['details']['name'] = guild.name
                guild_data['details']['guild_creation'] = math.ceil(
                    guild.created_at.timestamp())
                guild_data['details']['owner'] = str(guild.owner.id)
                guild_data['details']['update'] = time.time()
                update = True
            if time.time() - guild_data['details']['detailed']['update'] > 300:
                detailed = self.extract_guild_detailed(self, guild)
                guild_data['details']['detailed'] = detailed
                guild_data['details']['detailed']['update'] = time.time()
                guild_data['details']['members']['bots'] = detailed['bots']
                guild_data['details']['members']['members'] = detailed[
                    'members']
                guild_data['details']['members'][
                    'all'] = detailed['bots'] + detailed['members']
                del guild_data['details']['detailed']['bots']
                del guild_data['details']['detailed']['members']
                update = True
            if time.time(
            ) - guild_data['details']['guild']['channels']['update'] > 1800:
                channels = self.extract_channels(self, guild)
                guild_data['guild']['channels'] = channels
                guild_data['guild']['channels']['update'] = time.time()
                update = True

        if update or new:
            if new:
                rockutils.pprint(f"Creating information for {guild_id}",
                                 prefix="get_guild_info",
                                 prefix_colour="light green")
                await r.table("guilds").insert(guild_data).run(
                    self.bot.connection)
            else:
                await update_guild_info(self,
                                        guild_id,
                                        guild_data,
                                        refer="get_guild_info")

        return guild_data
Exemplo n.º 4
0
from PIL import Image, ImageDraw, ImageFile, ImageFont, ImageOps, ImageSequence
from quart import Quart, Response, jsonify, request, send_file
from discord import Webhook, RequestsWebhookAdapter

import imageio
import psutil
import ujson as json
import psycopg2
import sys
from rockutils import rockutils

ImageFile.LOAD_TRUNCATED_IMAGES = True

app = Quart(__name__)
gc.enable()
config = rockutils.load_json("cfg/config.json")
cdn_path = config['cdn']['location']
deadimage = Image.open("deadimage.png")
defaulticon = Image.open("0.png")

custom_path = "CustomImages"
normal_path = "Images"
distribution_path = "Output"
fallback_back = "default.png"

image_caches = dict()
easter = False
shouldcache = False

log = logging.getLogger('quart.serving')
log.setLevel(logging.ERROR)
Exemplo n.º 5
0
 def __init__(self, bot):
     self.bot = bot
     self.dump = rockutils.load_json("dump.json")
Exemplo n.º 6
0
import string
import random
import time
import asyncio
import math
import copy
import psutil
import os
import logging

from quart import Quart, g, websocket, session, redirect, request, url_for, jsonify, render_template, send_file, abort
from rockutils import rockutils

import ujson as json

config = rockutils.load_json("data/bot_data.json")

app = Quart(__name__)

log = logging.getLogger('quart.serving')
log.setLevel(logging.ERROR)

activejobs = {}
clusterjobs = {}

clusterstatus = {}

default = {
    "pid": "",
    "cpus": "",
    "cores": [],