Disable activation token and mastership mechanism

This commit is contained in:
Schimon Jehudah 2023-12-05 08:18:29 +00:00
parent ecdcfe9c22
commit ba97c33695
5 changed files with 170 additions and 137 deletions

View file

@ -14,32 +14,29 @@ TODO
""" """
from aiohttp import ClientError from aiohttp import ClientError, ClientSession, ClientTimeout
from aiohttp import ClientSession
from aiohttp import ClientTimeout
from asyncio import TimeoutError from asyncio import TimeoutError
from asyncio.exceptions import IncompleteReadError from asyncio.exceptions import IncompleteReadError
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from feedparser import parse from feedparser import parse
from http.client import IncompleteRead from http.client import IncompleteRead
from lxml import html from lxml import html
from datetimehandler import now from datetimehandler import now, rfc2822_to_iso8601
from datetimehandler import rfc2822_to_iso8601
from confighandler import get_list from confighandler import get_list
from listhandler import is_listed from listhandler import is_listed
from sqlitehandler import add_entry_and_set_date from sqlitehandler import (
from sqlitehandler import insert_feed add_entry_and_set_date,
from sqlitehandler import check_entry_exist insert_feed,
from sqlitehandler import check_feed_exist check_entry_exist,
from sqlitehandler import get_feeds_url check_feed_exist,
from sqlitehandler import remove_nonexistent_entries get_feeds_url,
from sqlitehandler import update_source_status remove_nonexistent_entries,
from sqlitehandler import update_source_validity update_source_status,
update_source_validity
)
from urllib import error from urllib import error
# from xml.etree.ElementTree import ElementTree, ParseError # from xml.etree.ElementTree import ElementTree, ParseError
from urllib.parse import urljoin from urllib.parse import urljoin, urlsplit, urlunsplit
from urllib.parse import urlsplit
from urllib.parse import urlunsplit
# NOTE Why (if res[0]) and (if res[1] == 200)? # NOTE Why (if res[0]) and (if res[1] == 200)?
async def download_updates(db_file, url=None): async def download_updates(db_file, url=None):
@ -328,7 +325,7 @@ async def view_entry(url, num):
# "For more information, visit " # "For more information, visit "
# "https://pythonhosted.org/feedparser/bozo.html" # "https://pythonhosted.org/feedparser/bozo.html"
# ).format(url) # ).format(url)
msg = await probe_page(view_entry, url, result[0], num) msg = await probe_page(view_entry, url, result[0], num=num)
return msg return msg
except ( except (
IncompleteReadError, IncompleteReadError,

View file

@ -7,8 +7,7 @@ https://feedparser.readthedocs.io/en/latest/date-parsing.html
from datetime import datetime from datetime import datetime
from dateutil.parser import parse from dateutil.parser import parse
from email.utils import parsedate from email.utils import parsedate, parsedate_to_datetime
from email.utils import parsedate_to_datetime
async def now(): async def now():
""" """

View file

@ -22,10 +22,8 @@ from datetime import date
import confighandler as confighandler import confighandler as confighandler
# from slixfeed.datahandler import join_url # from slixfeed.datahandler import join_url
import datahandler as datahandler import datahandler as datahandler
from datetimehandler import current_time from datetimehandler import current_time, rfc2822_to_iso8601
from datetimehandler import rfc2822_to_iso8601 from sqlite3 import connect, Error
from sqlite3 import connect
from sqlite3 import Error
# from eliot import start_action, to_file # from eliot import start_action, to_file
# # with start_action(action_type="list_feeds()", db=db_file): # # with start_action(action_type="list_feeds()", db=db_file):

View file

@ -46,12 +46,13 @@ import slixmpp
from datahandler import download_updates from datahandler import download_updates
from datetimehandler import current_time from datetimehandler import current_time
from filehandler import initdb from filehandler import initdb, get_default_dbdir
from filehandler import get_default_dbdir from sqlitehandler import (
from sqlitehandler import get_entry_unread get_entry_unread,
from sqlitehandler import get_settings_value get_settings_value,
from sqlitehandler import get_number_of_items get_number_of_items,
from sqlitehandler import get_number_of_entries_unread get_number_of_entries_unread
)
# from xmpphandler import Slixfeed # from xmpphandler import Slixfeed
import xmpphandler as xmpphandler import xmpphandler as xmpphandler

View file

@ -53,30 +53,36 @@ import asyncio
import logging import logging
# import os # import os
import slixmpp import slixmpp
from slixmpp.exceptions import IqError
from random import randrange from random import randrange
from datahandler import add_feed from datahandler import (
from datahandler import add_feed_no_check add_feed,
from datahandler import feed_to_http add_feed_no_check,
from datahandler import view_entry feed_to_http,
from datahandler import view_feed view_entry,
view_feed
)
from datetimehandler import current_time from datetimehandler import current_time
from filehandler import initdb from filehandler import initdb
from listhandler import add_to_list from listhandler import add_to_list, remove_from_list
from listhandler import remove_from_list from sqlitehandler import (
from sqlitehandler import get_settings_value get_settings_value,
from sqlitehandler import set_settings_value set_settings_value,
from sqlitehandler import mark_source_as_read mark_source_as_read,
from sqlitehandler import last_entries last_entries,
from sqlitehandler import list_feeds list_feeds,
from sqlitehandler import remove_feed remove_feed,
from sqlitehandler import search_feeds search_feeds,
from sqlitehandler import statistics statistics,
from sqlitehandler import toggle_status toggle_status
from taskhandler import clean_tasks_xmpp )
from taskhandler import start_tasks_xmpp from taskhandler import (
from taskhandler import refresh_task clean_tasks_xmpp,
from taskhandler import send_status start_tasks_xmpp,
from taskhandler import send_update refresh_task,
send_status,
send_update
)
from slixmpp.plugins.xep_0363.http_upload import FileTooBig, HTTPError, UploadServiceNotFound from slixmpp.plugins.xep_0363.http_upload import FileTooBig, HTTPError, UploadServiceNotFound
# from slixmpp.plugins.xep_0402 import BookmarkStorage, Conference # from slixmpp.plugins.xep_0402 import BookmarkStorage, Conference
from slixmpp.plugins.xep_0048.stanza import Bookmarks from slixmpp.plugins.xep_0048.stanza import Bookmarks
@ -237,24 +243,26 @@ class Slixfeed(slixmpp.ClientXMPP):
async def join_muc(self, inviter, muc_jid): async def join_muc(self, inviter, muc_jid):
token = await initdb( # token = await initdb(
muc_jid, # muc_jid,
get_settings_value, # get_settings_value,
"token" # "token"
) # )
if token != "accepted": # if token != "accepted":
token = randrange(10000, 99999) # token = randrange(10000, 99999)
await initdb( # await initdb(
muc_jid, # muc_jid,
set_settings_value, # set_settings_value,
["token", token] # ["token", token]
) # )
self.send_message( # self.send_message(
mto=inviter, # mto=inviter,
mbody=( # mbody=(
"Send activation token {} to groupchat xmpp:{}?join." # "Send activation token {} to groupchat xmpp:{}?join."
).format(token, muc_jid) # ).format(token, muc_jid)
) # )
print("muc_jid")
print(muc_jid)
self.plugin['xep_0045'].join_muc( self.plugin['xep_0045'].join_muc(
muc_jid, muc_jid,
"Slixfeed (RSS News Bot)", "Slixfeed (RSS News Bot)",
@ -265,6 +273,13 @@ class Slixfeed(slixmpp.ClientXMPP):
result = await self.plugin['xep_0048'].get_bookmarks() result = await self.plugin['xep_0048'].get_bookmarks()
bookmarks = result["private"]["bookmarks"] bookmarks = result["private"]["bookmarks"]
conferences = bookmarks["conferences"] conferences = bookmarks["conferences"]
print("result")
print(result)
print("bookmarks")
print(bookmarks)
print("conferences")
print(conferences)
breakpoint()
mucs = [] mucs = []
for conference in conferences: for conference in conferences:
jid = conference["jid"] jid = conference["jid"]
@ -596,19 +611,42 @@ class Slixfeed(slixmpp.ClientXMPP):
if (msg['muc']['nick'] == "Slixfeed (RSS News Bot)" or if (msg['muc']['nick'] == "Slixfeed (RSS News Bot)" or
not msg["body"].startswith("!")): not msg["body"].startswith("!")):
return return
token = await initdb( # token = await initdb(
# jid,
# get_settings_value,
# "token"
# )
# if token == "accepted":
# operator = await initdb(
# jid,
# get_settings_value,
# "masters"
# )
# if operator:
# if nick not in operator:
# return
approved = False
role = self.plugin['xep_0045'].get_jid_property(
jid, jid,
get_settings_value, msg["from"],
"token" "role")
) if role == "moderator":
if token == "accepted": approved = True
operator = await initdb( # TODO Implement a list of temporary operators
jid, # Once an operator is appointed, the control would last
get_settings_value, # untile the participant has been disconnected from MUC
"masters" # An operator is a function to appoint non moderators.
) # Changing nickname is fine and consist of no problem.
if operator: # if not approved:
if nick not in operator: # operator = await initdb(
# jid,
# get_settings_value,
# "masters"
# )
# if operator:
# if nick in operator:
# approved = True
if not approved:
return return
# # Begin processing new JID # # Begin processing new JID
@ -649,30 +687,30 @@ class Slixfeed(slixmpp.ClientXMPP):
print(jid) print(jid)
await self.autojoin_muc() await self.autojoin_muc()
case _ if message_lowercase.startswith("activate"): # case _ if message_lowercase.startswith("activate"):
if msg["type"] == "groupchat": # if msg["type"] == "groupchat":
acode = message[9:] # acode = message[9:]
token = await initdb( # token = await initdb(
jid, # jid,
get_settings_value, # get_settings_value,
"token" # "token"
) # )
if int(acode) == token: # if int(acode) == token:
await initdb( # await initdb(
jid, # jid,
set_settings_value, # set_settings_value,
["masters", nick] # ["masters", nick]
) # )
await initdb( # await initdb(
jid, # jid,
set_settings_value, # set_settings_value,
["token", "accepted"] # ["token", "accepted"]
) # )
action = "{}, your are in command.".format(nick) # action = "{}, your are in command.".format(nick)
else: # else:
action = "Activation code is not valid." # action = "Activation code is not valid."
else: # else:
action = "This command is valid for groupchat only." # action = "This command is valid for groupchat only."
case _ if message_lowercase.startswith("add"): case _ if message_lowercase.startswith("add"):
message = message[4:] message = message[4:]
url = message.split(" ")[0] url = message.split(" ")[0]
@ -937,30 +975,30 @@ class Slixfeed(slixmpp.ClientXMPP):
).format(val) ).format(val)
else: else:
action = "Missing value." action = "Missing value."
case _ if message_lowercase.startswith("mastership"): # case _ if message_lowercase.startswith("mastership"):
key = message[:7] # key = message[:7]
val = message[11:] # val = message[11:]
if val: # if val:
names = await initdb( # names = await initdb(
jid, # jid,
get_settings_value, # get_settings_value,
key # key
) # )
val = await add_to_list( # val = await add_to_list(
val, # val,
names # names
) # )
await initdb( # await initdb(
jid, # jid,
set_settings_value, # set_settings_value,
[key, val] # [key, val]
) # )
action = ( # action = (
"Operators\n" # "Operators\n"
"```\n{}\n```" # "```\n{}\n```"
).format(val) # ).format(val)
else: # else:
action = "Missing value." # action = "Missing value."
case "new": case "new":
await initdb( await initdb(
jid, jid,
@ -1345,14 +1383,14 @@ def print_help():
"GROUPCHAT OPTIONS\n" "GROUPCHAT OPTIONS\n"
" ! (command initiation)\n" " ! (command initiation)\n"
" Use exclamation mark to initiate an actionable command.\n" " Use exclamation mark to initiate an actionable command.\n"
" activate CODE\n" # " activate CODE\n"
" Activate and command bot.\n" # " Activate and command bot.\n"
" demaster NICKNAME\n" # " demaster NICKNAME\n"
" Remove master privilege.\n" # " Remove master privilege.\n"
" mastership NICKNAME\n" # " mastership NICKNAME\n"
" Add master privilege.\n" # " Add master privilege.\n"
" ownership NICKNAME\n" # " ownership NICKNAME\n"
" Set new owner.\n" # " Set new owner.\n"
"\n" "\n"
"FILTER OPTIONS\n" "FILTER OPTIONS\n"
" allow +\n" " allow +\n"