예제 #1
0
 async def predicate(ctx):
     config = jthon.load('./config')
     contributors = list(config.get('contributor').data)
     if str(ctx.author.id) in contributors:
         return True
     else:
         raise NotContributor
예제 #2
0
async def profile(ctx, user: str = None):
    if not user:
        user = users.get('users').get(str(ctx.author.id))
        async with bot.aiohttp.get(f"{base}{user}", headers=headers) as resp:
            if resp.status == 200:
                e = discord.Embed(
                    title='Faceit Profile',
                    colour=discord.Colour(0x278d89),
                )
                load_response_into_jthon = jthon.load('data', await
                                                      resp.json())
                avatar = load_response_into_jthon.get("avatar")
                get_elo = load_response_into_jthon.get("games").get(
                    "csgo").get("faceit_elo")
                get_skill_level = load_response_into_jthon.get("games").get(
                    "csgo").get("skill_level")
                e.set_thumbnail(url=avatar)
                e.add_field(name='Elo', value=get_elo, inline=False)
                e.add_field(name='Skill Level',
                            value=get_skill_level,
                            inline=True)
                if get_skill_level.data < 10:
                    next_level = rank_up_dict.get('levels').get(
                        str(get_skill_level.data + 1))
                    tnl = next_level - get_elo.data
                e.add_field(name='Elo TNL', value=str(tnl), inline=False)
                e.set_footer(text=f"https://www.faceit.com/en/players/{user}")
                await ctx.send(embed=e)

    else:
        print('user provided')
예제 #3
0
 def __init__(self, bot):
     self.bot = bot
     self.bot.running_lottos = []
     self.bot.guildconfigs = []
     self.bot.itemdict = {}
     self.bot.fullitems = {}
     self.bot.addedids = []
     self.bot.propdict = jthon.load('./cogs/util/data/propertydict').get(
         'properties')
예제 #4
0
    def __init__(self, settings="settings"):
        settings += "bot_settings.json"
        if not os.path.isfile(settings):
            self.config = jthon.load(settings)
            self.prefix = ["m?"]
            self.description = None
            self.pm_help = False
            self.case_insensitive = False
            self.get_info()
            self.config.data = {
                "traceback": False,
                "Bot Settings": {
                    "command_prefix": self.prefix,
                    "coowners": [598625004279693460, 616582088845688843],
                    "description": self.description,
                    "pm_help": self.pm_help,
                    "case_insensitive": self.case_insensitive,
                },
            }
            self.config.save()

        self.config = jthon.load(settings)
# Import Stack
import discord
from discord.ext import commands
import jthon
from pathlib import Path
import os
from cogs.util.errors import NotContributor

# Variable Defs
config = jthon.load('config')
TOKEN = str(config.get("token")) #pulls the bot token from the hidden config file
bot = commands.Bot(command_prefix="^")

# Function Defs
def get_prefix(bot, message): #determines the prefix from the config file, if there isn't one, it defaults to "$"
    prefix = config.get('prefix')
    if not prefix:
        prefix = '^'
    return commands.when_mentioned_or(*prefix)(bot, message)

def load_some_cogs(): #loads all available extensions, can also be done manually when the admin cog is loaded
    bot.startup_extensions = []
    path = Path('./cogs')
    for dirpath, dirnames, filenames in os.walk(path):
        if dirpath.strip('./') == str(path):
            for cog in filenames:
                if cog.endswith('.py') and not cog.startswith('_'):
                    extension = 'cogs.'+cog[:-3]
                    bot.startup_extensions.append(extension)

    if __name__ == "__main__":
예제 #6
0
import requests
import jthon
from datetime import datetime, timezone


def event_time(time):
    time = time // 1000.0
    return ''.join(
        str(datetime.fromtimestamp(time, tz=timezone.utc))[:-6].split())


file = jthon.load('EarthquakeExample')  #load the file into jthon
start = file.get('start').get('time')  #get something from the file
resp = requests.get(
    f"https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&latitude=61.2140767&longitude=-149.8454911&maxradius=15&starttime={start}"
)
data = resp.json()
if data["metadata"]["count"] != 0:
    time_check = event_time(data['features'][0]['properties']['time'])
    if time_check not in str(start):
        for x in range(data["metadata"]["count"]):
            time = event_time(data['features'][x]['properties']['time'])
            if time not in file.get('items'):
                place = data['features'][x]['properties']['place']
                mag = data['features'][x]['properties']['mag']
                print(
                    f'A magnitude {mag} at {place} reported at {time[-8:]}|{time[:10]}'
                )
                file['items'][time] = place
                file.save()
예제 #7
0
 async def credits(self, ctx):
     config = jthon.load('./config')
     contributors = list(config.get('contributors').data)
     await ctx.send(contributors)
예제 #8
0
                                "MemberID"	INTEGER NOT NULL,
                                "GuildID"	INTEGER NOT NULL,
                                PRIMARY KEY("ID" AUTOINCREMENT)
                            )""")
        await bot.db.commit()
    else:
        bot.db = await aiosqlite.connect("photopicker.db")


class Fetch:
    def __init__(self, bot):
        self.bot = bot

    async def all(self, *arg):
        get = await self.bot.db.execute(*arg)
        results = await get.fetchall()
        return results

    async def one(self, *arg):
        get = await self.bot.db.execute(*arg)
        results = await get.fetchone()
        return results


bot.config = jthon.load('data')['config']
bot.fetch = Fetch(bot)
bot.loop.create_task(create_dbconnect())
bot.loop.create_task(create_aiohttp())
load_extensions()
bot.run(bot.config.get('token'))
예제 #9
0
from optparse import OptionParser  #TODO: Update to a non-deprecated module
import jthon
from discord.ext import commands
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager

OPTIONS = webdriver.ChromeOptions()
OPTIONS.add_argument('--headless')
OPTIONS.add_argument('--no-sandbox')
OPTIONS.add_argument('--disable-dev-shm-usage')
DRIVER = webdriver.Chrome(chrome_options=OPTIONS,
                          executable_path=ChromeDriverManager().install())
CONFIG = jthon.load('config')

#Config
PARSER = OptionParser(
)  #TODO: I'm not sure what options this parses. It claims it's not a unused variable but I'm skeptical.
#-----functions-----


def is_passchannel(ctx):  #only exists to control usage
    """Checks if the channel is the password checking channel."""
    return ctx.message.channel.id == 678708790878797825


def teardown_method():
    DRIVER.quit()
예제 #10
0
import jthon
file = jthon.load('test_file')
urls = file.find('url', limit=2)
print(
    f"Number of results limited to [{len(urls)}]: {', '.join(str(url) for url in urls)}"
)
title = file.get('data').get('children')[1].get('data').get('title')
print(title)
file['data']['dist'] = 25
file.save(sort_keys=None)
예제 #11
0
import discord
from discord.ext import commands
import aiohttp
import jthon

bot = commands.Bot(command_prefix='?', )
token = 'DISCORD_TOKEN_HERE'
headers = {
    "Accept": "application/json",
    "Authorization": "Bearer FACEIT_API_TOKEN_HERE"
}
users = jthon.load('users')
base = "https://open.faceit.com/data/v4/players?nickname="
rank_up_dict = {
    'levels': {
        '1': 800,
        '2': 801,
        '3': 951,
        '4': 1101,
        '5': 1251,
        '6': 1401,
        '7': 1551,
        '8': 1701,
        '9': 1851,
        '10': 2001
    }
}


@bot.event
async def on_ready():
예제 #12
0
import logging
import traceback
from pathlib import Path

import discord
import jthon
from discord.ext import commands

from .. import config
from . import checks, query_logger

path = Path("Momento", "database", "json", "log_settings.json")
file = jthon.load(path.as_posix())
if not path.is_file():
    file.data = {
        "log_level": logging.INFO,
        "log_error": False,
        "log_message": False,
        "log_message_edit": False,
        "log_command": False,
        "log_command_error": False,
        "traceback": False,
    }
    file.save()

LOGS = logging.getLogger("discord")
LOGS.setLevel(logging.INFO)
HANDLER = logging.FileHandler(
    filename="discord.log",
    encoding="utf-8",
    mode=config.get("config").get("logging_mode", "w"),
예제 #13
0
        self.url = URL(loop=loop)
        self.api = API(loop=loop, key=key)


class Fetch:
    def __init__(self, bot):
        self.bot = bot

    async def all(self, *arg):
        get = await self.bot.db.execute(*arg)
        results = await get.fetchall()
        return results

    async def one(self, *arg):
        get = await self.bot.db.execute(*arg)
        results = await get.fetchone()
        return results



bot.fetch = Fetch(bot)
bot.loop.create_task(create_dbconnect())
bot.config = jthon.load('data')
bot.cogstuff = jthon.load('cogcheck')
bot.cogcheck = bot.cogstuff.get('guilds')
token = bot.config.get('config').get('token').data
bot.torn_key = bot.config.get('config').get('torn_token').data
bot.torn = Torn(bot.loop, key=bot.torn_key)
load_extensions()
bot.run(token)