def set_vip(user_id: int): con, cur = Db.connect() try: cur.execute("UPDATE public.user SET vip = TRUE WHERE user_id = {}::text".format(str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def unset_mute(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.muted WHERE user_id = {}::text and guild_id = {}::text;".format(str(user_id), str(guild_id))) except Exception as err: print(err) con.rollback() con.commit()
def unset_level(level: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.roles WHERE level = {} and guild_id = {}::text;".format(level, str(guild_id))) except Exception as err: print(err) con.rollback() con.commit()
def update_name(user_id: int, name: str): con, cur = Db.connect() try: cur.execute("UPDATE public.user SET user_name = %s WHERE user_id = %s::text", ( name, str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def set_mute(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.muted ( guild_id, user_id) VALUES ( {}::text, {}::text );".format(str(guild_id), str(user_id)) ) except Exception as err: print(err) con.rollback() con.commit()
def delete_ignored_chan(guild_id: int, chan_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.rankings_chan WHERE guild_id = {}::text AND chan_id = {}::text;" .format(str(guild_id), str(chan_id))) except Exception as err: print(err) con.rollback() con.commit()
def set_ignored_chan(guild_id: int, chan_id: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.rankings_chan ( guild_id, chan_id) VALUES ({}::text , {}::text );" .format(str(guild_id), str(chan_id))) except Exception as err: print(err) con.rollback() con.commit()
def delete_from_user(user_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.sanctions WHERE user_id = {}::text;". format(str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def get_vips(): con, cur = Db.connect() try: cur.execute("SELECT * FROM public.user WHERE vip = TRUE") except Exception as err: print(err) con.rollback() rows = cur.fetchall() if rows: return UserDB.users_from_row(rows) return "Error : No VIP"
def unset_lover(user_id: int, lover_id: int): con, cur = Db.connect() try: cur.execute("UPDATE public.user SET married = FALSE , lover = %s WHERE user_id = %s::text", (None, str(user_id))) cur.execute( "UPDATE public.user SET married = FALSE, lover= %s WHERE user_id = %s::text", (None, str(lover_id))) except Exception as err: print(err) con.rollback() con.commit()
def create_user_one(user_id: int, cat_id: int, chan_id: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.private_users ( cat_id, user_id, chan_id) VALUES ( {}::text, {}::text, {}::text);" .format(str(cat_id), str(user_id), str(chan_id))) except Exception as err: print(err) con.rollback() con.commit()
def delete_one(guild_id: int, cat_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.private WHERE guild_id = {}::text and cat_id = {}::text;" .format(str(guild_id), str(cat_id))) except Exception as err: print(err) con.rollback() con.commit()
def create_ranking(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.rankings ( guild_id, level, reach, total, user_id, xp) " " VALUES ( {}::text, 0, 20, 0, {}::text, 0 );".format( str(guild_id), str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def delete_channel(chan_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.chan_network WHERE chan_id = {}::text;". format(str(chan_id))) except Exception as err: print(err) con.rollback() con.commit()
def unblock_user(user_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.user_network WHERE user_id = {}::text;". format(str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def reset_user(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "UPDATE public.rankings SET level = 0, reach = 20, total = 0, xp = 0 " "WHERE guild_id = {}::text AND user_id = {}::text;".format( str(guild_id), str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def create(user: User): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.user ( crew, description, user_id, vip, user_name) " "VALUES ( %s, %s, %s::text, %s, %s::text);", (user.crew, user.description, str(user.user_id), str(user.vip), user.user_name)) except Exception as err: print(err) con.rollback() con.commit()
def set_author(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.anon_users ( user_id, guild_id) VALUES ( %s::text, %s::text );", (str(user_id), str(guild_id))) except Exception as err: print(err) con.rollback() con.commit()
def block_user(user_id: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.user_network ( user_id) VALUES ( {}::text );" .format(str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def unblock_anon(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "UPDATE public.anon_users SET blocked = false WHERE user_id = {}::text AND guild_id = {}::text;" .format(str(user_id), str(guild_id))) except Exception as err: print(err) con.rollback() con.commit()
def unset_channel(guild_id: int): con, cur = Db.connect() try: cur.execute( "DELETE FROM public.anon WHERE guild_id = {}::text;".format( str(guild_id))) except Exception as err: print(err) con.rollback() con.commit()
def get_one_from_level(level: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "SELECT * FROM public.roles WHERE level = {} and guild_id = {}::text;".format(level, str(guild_id))) except Exception as err: print(err) con.rollback() rows = cur.fetchone() if rows: return rows
def get_sanction(sanction_id: int) -> Sanction: con, cur = Db.connect() try: cur.execute( "SELECT * FROM public.sanctions WHERE sanction_id = {}::text;". format(str(sanction_id))) except Exception as err: print(err) con.rollback() rows = cur.fetchone() if rows: return SanctionsDB.sanction_from_row(rows)
def update_user_id(user_id: id, guild_id: id, level: int, reach: int, xp: int): con, cur = Db.connect() try: cur.execute( "UPDATE public.rankings SET level = {}, reach = {}, xp = {} " "WHERE guild_id = {}::text AND user_id = {}::text;".format( level, reach, xp, str(guild_id), str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def set_level(role_id: int, guild_id: int, level: int): con, cur = Db.connect() try: cur.execute( "INSERT INTO public.roles ( guild_id, role_id, level) VALUES ( {}::text, {}::text, {} );".format( str(guild_id), str(role_id), level) ) except Exception as err: print(err) con.rollback() con.commit()
def update_user(user_id: int, guild_id: int, ranking: dict): con, cur = Db.connect() try: cur.execute( "UPDATE public.rankings SET level = {}, reach = {}, total = {}, xp = {} " "WHERE guild_id = {}::text AND user_id = {}::text;".format( ranking['level'], ranking['reach'], ranking['total'], ranking['xp'], str(guild_id), str(user_id))) except Exception as err: print(err) con.rollback() con.commit()
def is_muted(user_id: int, guild_id: int): con, cur = Db.connect() try: cur.execute( "SELECT * FROM public.muted WHERE user_id = {}::text and guild_id = {}::text;".format(str(user_id), str(guild_id))) except Exception as err: print(err) con.rollback() rows = cur.fetchone() if rows: return True return False
def get_channel(guild_id: int): con, cur = Db.connect() try: cur.execute( "SELECT * FROM public.anon WHERE guild_id = {}::text;".format( str(guild_id))) except Exception as err: print(err) con.rollback() rows = cur.fetchone() if rows: return AnonDB.rows_to_dict(rows) return None
def is_ignored_chan(chan_id: int): con, cur = Db.connect() try: cur.execute( "SELECT * FROM public.rankings_chan WHERE chan_id = {}::text;". format(str(chan_id))) except Exception as err: print(err) con.rollback() rows = cur.fetchone() if rows: return True return False
def set_lover(user_id: int, lover_id: int): con, cur = Db.connect() try: cur.execute("UPDATE public.user SET married = TRUE , lover = {}::text WHERE user_id = {}::text".format( str(lover_id), str(user_id))) cur.execute("UPDATE public.user SET married = TRUE , lover = {}::text WHERE user_id = {}::text".format( str(user_id), str(lover_id))) except Exception as err: print(err) con.rollback() con.commit()