def __init__(self, name, token): self.i_name = name if not Postgres.select(table="student", where="student_info='{}'".format(self.i_name)): student_id = Postgres.select(table="student", columns="max(student_id)")[0]["max"] if student_id: student_id = int(student_id) + 1 else: student_id = 1 info = NSTUAPI().get_student_info(token)[1] Postgres.insert(table="student", values=[student_id, info["FIO"]]) if not Postgres.select(table="groups", where="group_info='{}'".format( info["group"])): group_id = Postgres.select(table="groups", columns="max(group_id)")[0]["max"] if group_id: group_id = int(group_id) + 1 else: group_id = 1 Postgres.insert(table="groups", values=[group_id, info["group"]]) Postgres.insert(table="group_students", values=[group_id, student_id])
async def set(ctx, new_prefix): """changes the bot's prefix for this guild""" # instantiate database with Postgres() as db: # check if there's already an entry for this guild entry_exists = db.query( 'SELECT prefix FROM prefixes WHERE guild_id = %s', (ctx.guild.id, )) # if there is, then update the entry if entry_exists: db.execute('UPDATE prefixes SET prefix=%s WHERE guild_id = %s', (new_prefix, ctx.guild.id)) # else create a new entry for this guild else: db.execute('INSERT INTO prefixes VALUES (%s, %s)', (ctx.guild.id, new_prefix)) # check to see if we successfully wrote to the database by checking if a row was modified if db.cursor.rowcount == 1: await ctx.send( f':white_check_mark:⠀⠀**Success!**⠀my prefix is now `{new_prefix}`' ) # else something went wrong else: await ctx.send( '<:wrong:742105251271802910>⠀⠀**Error!!**⠀my prefix couldn\'t be changed because something went wrong' )
async def send_qr(request): req_data = await get_request(request) if req_data["string"] in QR: lector_id = LECTORS[0].get_id() pair_id = LECTORS[0].get_current_pair() student_ = NSTUAPI().get_student_info( req_data["token"], )[1] student = Postgres.select(table="student", where="student_info='{}'".format(student_['FIO']))[0] # group_ = Postgres.select( # table="group_students", # where="student_id='{}'".format(student['student_id']))[0] # group = Postgres.select(table="groups", where="group_id='{}'".format(group_["group_id"]))[0] # Postgres.insert(table="current_pars", [lector_id, pair_id, student["student_info"]]) print(lector_id, pair_id, student["student_info"], student['student_id']) Postgres.insert(table="pairs", values=[lector_id, pair_id, student['student_id']]) return get_response()
def authorize(self, password): lector = Postgres.select( "users", where="password='******' and username='******'".format( password, self.i_name ) ) if lector: self.i_authorized_flag = True self.i_id = lector[0]["id"] return self.get_id()
def get_starboard(self, guild_id): with Postgres() as db: starboard_from_db = db.query( 'SELECT * FROM starboard WHERE guild_id = %s', (guild_id, )) if starboard_from_db: starboard_settings = { "channel": self.bot.get_channel((starboard_from_db[0])[1]), "star_emoji": (starboard_from_db[0])[2], "count": (starboard_from_db[0])[3], "conf_emoji": (starboard_from_db[0])[4] } return starboard_settings else: return None
async def delete(self, ctx): """deletes the starboard for this guild""" if self.get_starboard(ctx.guild.id): with Postgres() as db: db.execute('DELETE FROM starboard WHERE guild_id = %s', (ctx.guild.id, )) if db.cursor.rowcount == 1: await ctx.send(content=None, embed=self.get_success_embed( ctx, "StarboardDeleted")) else: await ctx.send( "something went wrong, starboard could not be deleted") else: await ctx.send(content=None, embed=self.get_error_embed(ctx, "StarboardNotExist"))
async def create(self, ctx, channel: discord.TextChannel): """creates a starboard for this guild""" if not self.get_starboard(ctx.guild.id): with Postgres() as db: db.execute( "INSERT INTO starboard VALUES (%s, %s, DEFAULT, DEFAULT, DEFAULT)", (ctx.guild.id, channel.id)) if db.cursor.rowcount == 1: await ctx.send(content=None, embed=self.get_success_embed( ctx, "StarboardCreated")) else: await ctx.send( "something went wrong, starboard could not be created") else: await ctx.send(content=None, embed=self.get_error_embed( ctx, "StarboardAlreadyExists"))
def get_prefix(bot, message): """a callable prefix for our bot which can be customized by each guild""" # set default prefix default_prefix = ';' # check if we're outside a guild (like in a DM, etc.) if not message.guild: # only allow the default prefix or mention to be used in DMs return commands.when_mentioned_or(*default_prefix)(bot, message) with Postgres() as db: # check if this guild has a custom prefix prefix = db.query('SELECT prefix FROM prefixes WHERE guild_id = %s', (message.guild.id, )) # if so, return that prefix if prefix: return commands.when_mentioned_or(str(*prefix[0]))(bot, message) # otherwise return the default prefix return commands.when_mentioned_or(*default_prefix)(bot, message)
'NEBULArobo ([https://nebularobo.carrd.co/](https://nebularobo.carrd.co/))', inline=False) embed.add_field( name='Icon Artist', value= 'crankiereddy ([https://twitter.com/crankiereddy](https://twitter.com/crankiereddy))', inline=False) await ctx.send(content=None, embed=embed) # Here we load our extensions(cogs) listed above in [initial_extensions]. if __name__ == '__main__': for extension in initial_cogs: bot.load_extension(extension) with Postgres() as db: db.create_tables() @bot.event async def on_ready(): print( f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: {discord.__version__}\n' ) # Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url. print(f'Successfully logged in and booted...!') bot.run(os.environ.get("TOKEN"), bot=True, reconnect=True)