def test_url_regex(): for url in ["hpps://dagbot.com", "http//dagbot.com", "https://dagcom"]: try: Client.url_test(url) except Exception as e: print(str(e)) assert isinstance(e, errors.BadUrl)
async def makesession(self): self.session = aiohttp.ClientSession(loop=self.loop) self.logger.info('made session') self.dagpi = Client(self.data['dagpitoken'], loop=self.loop, session=self.session) self.logger.info("Dagpi Initialised")
async def test_no_auth(): c = Client("") try: await c.wtp() except Exception as e: assert isinstance(e, errors.Unauthorised) await c.close()
async def test_data(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) dat = await c.wtp() assert dat.name logo = await c.logo() assert isinstance(str(logo), str)
async def test_feature_check(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) try: await c.image_process('bad', 'https://dagbot-is.the-be.st/logo.png') except Exception as e: assert isinstance(e, errors.InvalidFeature)
async def test_ping(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) image_ping = await c.image_ping() await c.data_ping() await c.close() assert isinstance(image_ping, float)
def __init__(self, bot): self.bot = bot self.ses = bot.aiohttp_session self.dag_token = os.getenv("DAGPI") self.dagpi = Client(self.dag_token) self.deep_ai = os.getenv("DEEP_AI") self.radi_api = os.getenv("RADI_API")
async def test_image_unaccesible(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) try: await c.image_process(ImageFeatures.wanted(), "https://google.com") except Exception as e: assert isinstance(e, errors.ImageUnaccesible) await c.close()
def __init__(self, *args, **kwargs): super().__init__(get_prefix, description="A moderation / fun bot", intents=intents, allowed_mentions=discord.AllowedMentions.none(), activity=discord.Activity( type=discord.ActivityType.listening, name="@Penguin"), owner_ids={447422100798570496}, **kwargs) self._logger = logging.getLogger(__name__) self.loop = asyncio.get_event_loop() self.session = aiohttp.ClientSession() self.start_time = dt.datetime.now() with open("config.json") as res: self.config = json.load(res) self.ipc = ipc.Server(self, "localhost", self.config['ipc-port'], self.config['ipc-key']) self.load_extension("utils.ipc") self.db = self.loop.run_until_complete( asyncpg.create_pool(**self.config['db'])) # Cache stuff self.stats = {} self.prefixes = {} self.cache = {} self.disabledCommands = [] self.blacklistedUsers = [] self.reactionRoleDict = self.loop.run_until_complete( self.cache_reactionroles()) records = self.loop.run_until_complete( self.db.fetch("SELECT * FROM blacklist")) for i in records: self.blacklistedUsers.append(i["id"]) records = self.loop.run_until_complete( self.db.fetch("SELECT * FROM guild_config")) self.prefixes = dict( self.loop.run_until_complete( self.db.fetch("SELECT id, prefix FROM guild_config"))) for record in records: d = self.refresh_template(record) self.cache.update(d) self.get_announcement() self.dagpi_client = Client(self.config['dagpi']) self.command_stats = {} self.mystbin = mystbin.Client() self.load_cogs()
async def test_parameter_error(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) try: await c.image_process(ImageFeatures.discord(), "https://dagpi.xyz/dagpi.png") except Exception as e: assert isinstance(e, errors.ParameterError) await c.close()
def run(self, *args, **kwargs): # self.ipc.start() subprocess.check_output("pip install speedtest-cli", shell=True) self.before_invoke(self.start_typing) self.utils = utils self.deleted_message_cache = LimitedSizeDict() self.concurrency = [] self.color = 0x00ff6a self.psutil_process = psutil.Process() self._message_cache = {} self.prefixes = {} self.socket_receive = 0 self.start_time = time.time() self.socket_stats = Counter() self.command_counter = 0 self.commandsusages = Counter() self.session = aiohttp.ClientSession( headers={ "User-Agent": f"python-requests/2.25.1 The Anime Bot/1.1.0 Python/{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]} aiohttp/{aiohttp.__version__}" }) self.mystbin = mystbin.Client(session=self.session) self.vacefron_api = vacefron.Client(session=self.session, loop=self.loop) self.dag = Client(api_token, session=self.session, loop=self.loop) self.alex = alexflipnote.Client(alex_, session=self.session, loop=self.loop) self.ball = eight_ball.ball() self.zaneapi = aiozaneapi.Client(zane_api) for command in self.commands: self.command_list.append(str(command)) self.command_list.extend([alias for alias in command.aliases]) if isinstance(command, commands.Group): for subcommand in command.commands: self.command_list.append(str(subcommand)) self.command_list.extend([ f"{command} {subcommand_alias}" for subcommand_alias in subcommand.aliases ]) if isinstance(subcommand, commands.Group): for subcommand2 in subcommand.commands: self.command_list.append(str(subcommand2)) self.command_list.extend([ f"{subcommand} {subcommand2_alias}" for subcommand2_alias in subcommand2.aliases ]) if isinstance(subcommand2, commands.Group): for subcommand3 in subcommand2.commands: self.command_list.append(str(subcommand3)) self.command_list.extend([ f"{subcommand2} {subcommand3_alias}" for subcommand3_alias in subcommand3.aliases ]) super().run(*args, **kwargs)
async def test_image_special(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) img = await c.special_image_process("https://dagbot-is.the-be.st/logo.png") await c.close() img.write("some.png") assert isinstance(img, Image) assert isinstance(img.read(), bytes) assert isinstance(repr(img), str) assert isinstance(img.size(), int)
async def test_data(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) dat = await c.wtp() assert dat.name pickup = await c.pickup_line() assert pickup.line headline = await c.headline() assert headline.headline logo = await c.logo() await c.close() assert isinstance(str(logo), str)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.remove_command('help') self._commands = 0 self.currency_cache = {} self.session = ClientSession(loop=self.loop) self.dag = Client(dagpi_token, loop=self.loop) self.mystbin = mystbin.Client() self._start = time.time() self._prefixes = json.load(open('./prefixes.json', 'r')) self._banned = json.load(open('./bans.json', 'r')) self._edit_cache = {} self.cse = cse.Search(google_key) self.ipc = ipc.Server(self, 'localhost', 8080, secret_key=ipc_key) self.ball = ball() self.load_extension('jishaku') os.environ["JISHAKU_NO_UNDERSCORE"] = "true" os.environ["JISHAKU_NO_DM_TRACEBACK"] = "true" os.environ["JISHAKU_HIDE"] = "true"
def __init__(self, bot): self.bot = bot self.bot.dagpi = Client(Tokens.dagpi.value) self.description = "Some anime, manga and waifu related commands"
async def on_ready(): print(f"We have logged in as {bot.user}") bot.translator = Translator() bot.welcome_dict = dict( await bot.db.fetch("SELECT guild_id, channel_id FROM welcome")) bot.dagpi_client = Client(config['default']['dagpi'])
import discord from discord.ext import commands import secrets from asyncdagpi import Client from asyncdagpi import exceptions import asyncio, aiohttp from discord.ext.commands.cooldowns import BucketType API_CLIENT = Client(secrets.secrets_dagpi_token) class dagpiCog(commands.Cog): """Commands that utilise Daggy's API (dagpi.tk)""" def __init__(self, bot): self.bot = bot self.db_conn = bot.db_conn self.colour = 0xff9300 self.footer = 'Bot developed by DevilJamJar#0001\nWith a lot of help from ♿nizcomix#7532' self.thumb = 'https://styles.redditmedia.com/t5_3el0q/styles/communityIcon_iag4ayvh1eq41.jpg' @commands.command(aliases=['whosthatpokemon']) @commands.cooldown(1, 5, BucketType.user) @commands.max_concurrency(1, BucketType.channel) async def wtp(self, ctx): """Who's that pokemon!""" data = {'token': secrets.secrets_dagpi_token} url = 'https://dagpi.tk/api/wtp' async with aiohttp.ClientSession(headers=data) as cs, ctx.typing(): async with cs.get(url) as r: data = await r.json() qimg = data['question_image']
def __init__(self, bot): self.bot = bot self.dagpi = Client(Tokens.dagpi.value) self.description = "Some fun Image Manipulation Commands"
from asyncdagpi import Client API_CLIENT = Client('') async def wanted(image_url: str): response = await API_CLIENT.staticimage('wanted', image_url) with open('wanted.png' 'wb') as out: out.write(response.read()) import asyncio asyncio.get_event_loop().run_until_complete(wanted())
async def test_image(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) img = await c.image_process(ImageFeatures.pixel(), "https://dagbot-is.the-be.st/logo.png") assert isinstance(img, Image)
START_BAL = 250 token = open("toke.txt", "r").read() bot.load_extension("jishaku") hce = bot.get_command("help") hce.hidden = True dagpitoken = open("asy.txt", "r").read() robloxcookie = open("roblox.txt", "r").read() topastoken = open("top.txt", "r").read() chatbottoken = open("chat.txt", "r").read() hypixel = open("hypixel.txt", "r").read() bot.robloxc = f"{robloxcookie}" bot.hypixel = f"{hypixel}" bot.topken = f"{topastoken}" bot.chatbot = ac.Cleverbot(f"{chatbottoken}") bot.se = aiozaneapi.Client(f'{open("zane.txt", "r").read()}') bot.dagpi = Client(dagpitoken) bot.start_time = time.time() bot.thresholds = (10, 25, 50, 100) @bot.event async def on_connect(): print('bot connected')
from dotenv import load_dotenv from fuzzywuzzy import process from jishaku.paginators import PaginatorInterface, WrappedPaginator logger = logging.getLogger("discord") logger.setLevel(logging.DEBUG) handler = logging.FileHandler(filename="discord.log", encoding="utf-8", mode="w") handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s") ) logger.addHandler(handler) load_dotenv() TOKEN = os.getenv("DISCORD_TOKEN") dagpi = Client(os.getenv("DAGPI_TOKEN")) cleverbot = ac.Cleverbot(os.getenv("CHATBOT_TOKEN")) client = aiozaneapi.Client(os.getenv("ZANE_TOKEN")) async def get_prefix(bot, message): if message.guild is None: return "kb+" if message.guild.id in bot.prefixes.keys(): return commands.when_mentioned_or(*bot.prefixes[message.guild.id])(bot, message) prefixes = await bot.pg.fetchval( "select prefixes from prefixes where guild_id = $1", message.guild.id ) bot.prefixes[message.guild.id] = prefixes
def __init__(self, bot): self.bot = bot self.ses = bot.aiohttp_session token = os.getenv("DAGPI") self.dagpi = Client(token)
async def test_image_kwargs(): tok = os.getenv("DAGPI_TOKEN") c = Client(tok) discord = await c.image_process(ImageFeatures.discord(), "https://dagbot-is.the-be.st/logo.png", text="Message", username="******", dark=False) await c.close()
def __init__(self, bot): self.bot = bot self.dagpiclient = Client(os.getenv("ASYNCDAGPI"))
return prefix bot = commands.Bot(command_prefix=_check_prefix, intents=discord.Intents.all()) logging.getLogger('asyncio').setLevel(logging.CRITICAL) for filename in os.listdir('./cogs'): if filename.endswith('.py'): bot.load_extension(f'cogs.{filename[:-3]}') zane = aiozaneapi.Client(ZANE) bot.zane = zane bot.remove_command('help') dagp = Client(DAGPI) bot.dagp = dagp headers = {'Authorization': DAGPI} @tasks.loop(seconds=60) async def change_status(): status = f'Sakura Chan watching over {len(bot.guilds)} servers' await bot.change_presence(activity=discord.Game(status)) @bot.event async def on_ready(): print('we are ready to go. logged in as {0.user}'.format(bot)) change_status.start()
] else: return [ f'<@!{bot.user.id}> ', f'<@!{bot.user.id}>', bot.prefixes[str(message.guild.id)] ] bot = DMBot(command_prefix=get_prefix, intents=intents, case_insensitive=insensitiveCase, owner_ids={376129806313455616, 528290553415335947}) bot.remove_command('help') bot.commands_since_restart = 0 bot.currency_cache = {} bot.dag = Client(dagpi_token) bot.mystbin = mystbin.Client() bot.prefixes = json.load(open(prefixes_db_path, 'r')) bot.indent = utils.indent bot.edit_cache = {} bot.prefix_for = utils.prefix_for bot.codeblock = utils.codeblock def who(person, command): trigger = f'{person} just ran {command}' return trigger @bot.command() @commands.is_owner()