def __init__(self, bot): self.bot = bot self.JSON = "data/mod/autorole.json" self.antilinkpath = "data/mod/antilink.json" self.json = "data/general/starboard.json" self.starboardpath = dataIO.load_json(self.json) self.settings = dataIO.load_json(self.antilinkpath) self.data = dataIO.load_json(self.JSON)
def __init__(self, shard_count=None, shard_ids=None, send=None): title = "%shelp | patreon.com/watora" % globprefix streamer = "https://www.twitch.tv/monstercat" game = discord.Streaming(url=streamer, name=title) super().__init__(command_prefix=_prefix_callable, case_insensitive=True, description='', shard_ids=shard_ids, shard_count=shard_count, activity=game, fetch_offline_members=False, max_messages=None, heartbeat_timeout=300) self.pipe = send self.session = aiohttp.ClientSession(loop=self.loop) self.debug_mode = "" self.remove_command('help') self.init_ok = False self.tokens = dataIO.load_json("config/tokens.json") self.config = None self.now = None self.nowkpop = None self.mcnow = None self.prefixes_map = {} self.languages_map = {} self.owo_map = {} self.autosongs_map = {} self.loaded_languages = {} # Spotify Integration self.spotify = None
async def pl_append(self, ctx, name, *, links): """Appends a list of links to a playlist""" server = ctx.message.server author = ctx.message.author voice_channel = author.voice_channel if re.match(r'(https?://[^\s/$.?#].[^\s]*)', name): await send_cmd_help(ctx) file = self._find_playlist(server, name) if file == None: await self.bot.say("That playlist doesn't exist") return playlist = dataIO.load_json(file) if author.id != playlist["author"]: await self.bot.say("You are not the author of this playlist") return links = links.split() invalid_links = 0 for link in links: if re.match(r'(https?://[^\s/$.?#].[^\s]*)', link) != None: playlist["playlist"].append(link) else: invalid_links += 1 if invalid_links > 0: await self.bot.say(str(invalid_links) + " invalid links") dataIO.save_json(file, playlist) await self.bot.say("Added " + str(len(links) - invalid_links) + " links to " + name)
def run_paper(): api_cred = dataIO.load_json(API_CRED) url = api_cred["Alpaca"]["paper"]["url"] api_key = api_cred["Alpaca"]["paper"]["API_KEY_ID"] api_secret = api_cred["Alpaca"]["paper"]["API_SECRET_KEY"] active_check = pairs_trading_algo(url, api_key, api_secret) return active_check
def load(locale, module, key): file = f"locales/{locale}/{module}.json" if os.path.isfile(file): try: return dataIO.load_json(file)[key] except KeyError: return f"Missing locale {module}.{key}-{locale}" else: return f"Missing module {module}.{key}-{locale}"
def __init__(self, bot): self.bot = bot self.session = aiohttp.ClientSession() self.answers = ['It is certain', 'It is decidedly so', 'Without a doubt', 'Yes definitely', 'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good', 'Yes', 'Signs point to yes', 'Reply hazy try again', 'Very doubtful', 'Ask again later', 'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again', "Don't count on it", 'My reply is no', 'My sources say no', 'Outlook not so good'] self.JSON = 'data/general/rpssettings.json' self.settings = dataIO.load_json(self.JSON) self.rpssettings = defaultdict(lambda: rps_settings, self.settings) self.fnheaders = {'TRN-Api-Key': '52f2fbde-018d-47b5-9c7d-99990c0d3507'}
def __init__(self, bot, player): settings_file = "data/audio/settings.json" self.bot = bot self.settings = dataIO.load_json(settings_file) self.to_queue = {} self.queue = {} self.players = {} self.skip_votes = {} self.ytdl = youtube_dl.YoutubeDL(ytdl_options) self.time_alone = 0 self.repeat = 0 self.settings["avconv"] = player == "avconv" dataIO.save_json(settings_file, self.settings)
async def pl_queue(self, ctx, name): """Queues a playlist""" server = ctx.message.server author = ctx.message.author voice_channel = ctx.message.author.voice_channel if voice_channel == None: await self.bot.say( "You must be in a voice channel to use that command") return file = self._find_playlist(server, name) if file == None: await self.bot.say("That playlist doesn't exist") return playlist = dataIO.load_json(file) await self._queue_playlist(author.id, voice_channel, playlist["playlist"])
async def pl_remove(self, ctx, name): """Removes a playlist""" server = ctx.message.server author = ctx.message.author voice_channel = author.voice_channel file = self._find_playlist(server, name) if file == None: await self.bot.say("That playlist doesn't exist") return playlist = dataIO.load_json(file) if author.id != playlist["author"]: await self.bot.say("You are not the author of this playlist") return await self.bot.say("Deleted " + name) os.remove(file)
def check_files(): default = { "volume": 50, "max_length": 4500, "vote_enabled": True, "vote_threshold": 50, "title_status": True, "anvconv": False, "servers": {}, "sc_client_id": "hdTx9VMgRKaZjGttAZ0GheOtJobG9eYm" } settings_path = "data/audio/settings.json" if not os.path.isfile(settings_path): print("Creating default audio settings.json") dataIO.save_json(settings_path, default) settings = dataIO.load_json(settings_path) for key in default: if key not in settings: settings[key] = default[key] dataIO.save_json(settings_path, settings)
def check_files(): default = { "OUTPUT_REDIRECT": "pages", "OPEN_CMD": None, "MULTI_MSG_PAGING": False, "PM_PAGES": 20, "PAGES_LENGTH": 1500, "REPL_PREFIX": ['`'] } settings_path = "data/repl/settings.json" if not os.path.isfile(settings_path): print("Creating default repl settings.json...") dataIO.save_json(settings_path, default) else: # consistency check current = dataIO.load_json(settings_path) if current.keys() != default.keys(): for key in default.keys(): if key not in current.keys(): current[key] = default[key] print("Adding " + str(key) + " field to repl settings.json") dataIO.save_json(settings_path, current)
import sqlite3 from utils.dataIO import dataIO db_loc = dataIO.load_json("data/sqlite.config.json") db = sqlite3.connect(db_loc["file"]) dbc = db.cursor() def sanitize(val): return "".join(x for x in val if x.isalnum()) def create_table(name: str): name = sanitize(name) dbc.execute( f"CREATE TABLE IF NOT EXISTS {name}(sid INTEGER, name TEXT, value TEXT)" ) def delete_table(name: str): name = sanitize(name) dbc.execute(f"DROP TABLE IF EXISTS {name}") def read(table: str, sid: int, name: str): table = sanitize(table) try: dbc.execute(f"SELECT value FROM {table} WHERE sid=(?) AND name=(?)", (sid, name)) value = dbc.fetchall()[0][0] except IndexError:
def __init__(self, bot): self.bot = bot self.settings = dataIO.load_json("data/antiraid/settings.json")
import mysql.connector from utils.dataIO import dataIO db_cfg = dataIO.load_json("data/mysql.config.json") db = mysql.connector.connect(host=db_cfg["host"], autocommit=True, user=db_cfg["user"], password=db_cfg["pass"], database=db_cfg["db"]) dbc = db.cursor() def sanitize(val): return "".join(x for x in val if x.isalnum()) def check(): if not db.is_connected(): db.reconnect() def create_table(name: str): check() name = sanitize(name) dbc.execute( f"CREATE TABLE IF NOT EXISTS {name}(sid BIGINT UNSIGNED, name TEXT, value TEXT)" ) def delete_table(name: str): check()
def __init__(self, bot): self.bot = bot self.cooldown = 60 self.leader_board = dataIO.load_json("data/levels/leader_board.json") self.gettingxp = {} self.xp_gaining_channels = []
def __init__(self, bot): self.bot = bot self.JSON = "data/mod/autorole.json" self.data = dataIO.load_json(self.JSON)
def __init__(self, bot): self.bot = bot self.file_path = 'data/general/selfroles.json' self.data = dataIO.load_json(self.file_path)
def __init__(self, bot): self.bot = bot self.JSON = "data/general/logs.json" self.data = dataIO.load_json(self.JSON)
if len(args) == 1: print( "config.py: small utility to edit the configuration (for use with CLI)" ) print(f"- ./{args[0]} <file>: show config for file") print(f"- ./{args[0]} <file> <key>: show config for a specific key") print(f"- ./{args[0]} <file> <key> <value>: set config for a specific key") print(f"Example: ./{args[0]} config owner 481038581032403850") print( "To set value lists please edit the config manually (there isn't that much lists)" ) exit(0) try: config = dataIO.load_json("data/" + str(args[1]) + ".json") except FileNotFoundError: print(f"Missing data/{args[1]}.json file. Aborting.") exit(1) if len(args) == 2: print(f"Current configuration for data/{args[1]}.json is:") for i in config: print(f"{i}: {config[i]}") exit(0) if len(args) == 3: try: print(f"{args[2]}: {config[args[2]]}") except KeyError: print(f"'{args[2]}' is not present in the data/{args[1]}.json file.")
def __init__(self, bot): self.bot = bot self._giveaway_task = asyncio.get_event_loop().create_task( self.check_giveaway()) self._giveaway_file = 'data/general/giveaways.json' self._giveaway = dataIO.load_json(self._giveaway_file)
def __init__(self, bot): self.bot = bot self.file_path = "data/autorole/settings.json" self.settings = dataIO.load_json(self.file_path) self.users = {} self.messages = {}
def __init__(self, bot): self.bot = bot self.JSON = 'data/general/rps.json' self.settings = dataIO.load_json(self.JSON) self.settings = defaultdict(lambda: rps_settings, self.settings)
def __init__(self, bot): self.bot = bot self.file_path = "data/welcomer/settings.json" self.settings = dataIO.load_json(self.file_path) self.settings = defaultdict(lambda: settings, self.settings)
def __init__(self, bot): self.bot = bot self.location = 'data/economy/bank.json' self.settings = dataIO.load_json(self.location)
def __init__(self, bot): self.bot = bot self.direct = "data/modlogset/settings.json" self.ignore_list = dataIO.load_json("data/modlogset/ignorelist.json")
import discord from discord.ext import commands from utils.dataIO import dataIO from utils import db, checks, help, tools from utils import locale as loc from datetime import datetime config = dataIO.load_json("data/config.json") locales = dataIO.load_json("locales/locales.json") mn = "plugins.core" inv_d = "https://bot.proxymiity.fr/@/" class Core(commands.Cog, command_attrs=dict(hidden=True)): def __init__(self, bot): self.bot = bot @checks.bot_owner() @commands.command(help="shutdown_help", brief="shutdown_brief") async def shutdown(self, ctx, opt="normal"): db.delete_table("temp") print(loc.get(ctx, mn, "shutdown")) await ctx.send(loc.get(ctx, mn, "shutdown")) await self.bot.change_presence(status=tools.get_status("offline")) if "kill" in opt: exit(-1) else: await self.bot.close() @checks.bot_owner() @commands.group(help="plugin_help", brief="plugin_brief")
from utils.dataIO import dataIO from importlib import import_module driver = import_module(dataIO.load_json("data/config.json")["storage"]) tb_d = ["serversettings", "settings"] db_d = { "name": "Alter", "prefix": "::", "locale": "en_US", "status": "online", "presence_type": "game", "presence_value": "::help" } def check_defaults(): for t in tb_d: create_table(t) delete_table("temp") create_table("temp") for x in db_d: if not read("settings", 0, x): write("settings", 0, x, db_d[x]) def create_table(name: str): driver.create_table(name) def delete_table(name: str): driver.delete_table(name)
def __init__(self, bot): self.bot = bot self.config = dataIO.load_json('config.json')
def __init__(self, bot): self.bot = bot self.colours_file = "data/colours/colournames.json" self.colours = dataIO.load_json(self.colours_file)
def __init__(self, bot): self.bot = bot self.file_path = "data/antiad/settings.json" self.settings = dataIO.load_json(self.file_path)