def set_auth(i, irc, dbc): if not user_auth(i, irc, i.nickname): return f"{i.nickname}: You are not logged in with NickServ." dbc.execute('SELECT auth FROM weather WHERE nickname=?;', (i.nickname, )) fetch = dbc.fetchone() try: auth = fetch[0] except TypeError: # 'NoneType' object is not subscriptable auth = 0 if auth == 0: auth = 1 msg = f'{i.nickname}: weather: Enabled NickServ authentication.' elif auth == 1: auth = 0 msg = f'{i.nickname}: weather: Disabled NickServ authentication.' dbc.execute( "INSERT OR IGNORE INTO weather (nickname, auth) VALUES (?, ?);", (i.nickname, auth)) dbc.execute("UPDATE weather SET auth=? WHERE nickname=?;", (auth, i.nickname)) return msg
def is_authed(i, irc, dbc, nickname): auth = get_auth_mode(dbc, nickname) if auth == 0: return True if auth == 1 and user_auth(i, irc, nickname): return True return False
def is_allowed(i, irc, nickname, channel=""): if is_bot_owner(irc, nickname): if user_auth(i, irc, i.nickname): return True elif channel and is_channel_mod(irc, nickname, channel): return True else: return False elif channel and is_channel_mod(irc, nickname, channel): return True else: return False
def get_auth(i, irc, dbc): dbc.execute('SELECT auth FROM weather WHERE nickname=?;', (i.nickname, )) fetch = dbc.fetchone() try: auth = fetch[0] except TypeError: # 'NoneType' object is not subscriptable auth = 0 if auth == 0: return True elif auth == 1 and user_auth(i, irc, i.nickname): return True else: return False
def is_ignored(i, irc, user, query_nick): dbc = i.db_disk.cursor() try: dbc.execute("SELECT settings FROM ignore WHERE user = ?;", (user, )) j = dbc.fetchone()[0] o = json.loads(j) if o["ignore_all"]: return True elif o["registered_only"] and not user_auth(i, irc, query_nick): return True elif query_nick in o["ignored"]: return True else: return False except Exception: return False
def weather_auth(i, irc): msgtarget = i.msg.get_msgtarget() nickname = i.msg.get_nickname() args = i.msg.get_args() db = i.db_disk dbc = db.cursor() if not user_auth(i, irc, nickname): m = f"{nickname}: You are not logged in with NickServ." irc.out.notice(msgtarget, m) return new_auth = toggle_auth(dbc, nickname) db.commit() if new_auth == 1: m = f'{nickname}: weather: Enabled NickServ authentication.' elif new_auth == 2: m = f'{nickname}: weather: Disabled NickServ authentication.' irc.out.notice(msgtarget, m)
def npauth(i, irc, dbc): msgtarget = i.msg.get_msgtarget() nickname = i.msg.get_nickname() if not user_auth(i, irc, nickname): m = f"{nickname}: You need to be logged in to use this command" irc.out.notice(msgtarget, m) return if not is_authed(i, irc, dbc, nickname): m = f'{nickname}: You are not logged in.' irc.out.notice(msgtarget, m) return auth = toggle_auth_mode(dbc, nickname) i.db_disk.commit() if auth == 0: m = f"{nickname}: lastfm: Disabled authentication." elif auth == 1: m = f"{nickname}: lastfm: Enabled authentication." irc.out.notice(msgtarget, m)