Compare commits

...

3 Commits
develop ... ipm

@ -0,0 +1,16 @@
from settings.config import SQLACHEMY
from sqlalchemy import Table
from sqlalchemy.orm import declarative_base
Base = declarative_base()
class Ipm(Base):
"""
IPM model class.
"""
__table__ = Table(
"ipm",
Base.metadata,
autoload=True,
autoload_with=SQLACHEMY
)

@ -40,7 +40,7 @@ RQ_LEADERBOARD = os.environ.get('RQ_LEADERBOARD_FILE', '/opt/neeble/rqlb.list')
# Define the path for the --roulette leaderboard # Define the path for the --roulette leaderboard
ROULETTE_LEADERBOARD = os.environ.get('ROULETTE_LEADERBOARD', '/opt/neeble/roulette.list') ROULETTE_LEADERBOARD = os.environ.get('ROULETTE_LEADERBOARD', '/opt/neeble/roulette.list')
### THE 'PERMISSIONS' SET OF INSTRUCTIONS WILL BECOME DEPRECATED IN FAVOR OF THE IPM (Integrated Permissions Module)
## INSTRUCTIONS ON SETTING UP PERMISSIONS: ## INSTRUCTIONS ON SETTING UP PERMISSIONS:
# Permissions are now granular, more than one distinct role # Permissions are now granular, more than one distinct role
# can execute the commands, whatever roles are inside the # can execute the commands, whatever roles are inside the

@ -18,6 +18,7 @@ from utils.machine_monitor import Monitor
from utils.news_paper import News from utils.news_paper import News
from utils.tools import datetime_to_string, kbytes_to_gbytes from utils.tools import datetime_to_string, kbytes_to_gbytes
from utils.weather import displayweather, getweatherdata from utils.weather import displayweather, getweatherdata
from utils.ipm import ipm_check
client = commands.Bot(command_prefix='--', intents=Intents.all()) client = commands.Bot(command_prefix='--', intents=Intents.all())
@ -679,14 +680,16 @@ async def neeble_debug(bot:object) -> str:
Outputs debug data. Outputs debug data.
""" """
# TODO: This is repeated role checking code from the deletion function, better make this into one function itself # # TODO: This is repeated role checking code from the deletion function, better make this into one function itself
roles = [r.name for r in bot.author.roles] # roles = [r.name for r in bot.author.roles]
PermStatus = False # PermStatus = False
#
# if len(PERMISSIONS['dq']) < 1 or not len(set(PERMISSIONS['dq']).intersection(roles)) < 1:
# PermStatus = True
if len(PERMISSIONS['dq']) < 1 or not len(set(PERMISSIONS['dq']).intersection(roles)) < 1: PermStatus = ipm_check(bot.author.name, "mgmt.dbg")
PermStatus = True
if not PermStatus: if PermStatus is False:
return await bot.send("_And who the fuck do **YOU** think you are!?_.\n"\ return await bot.send("_And who the fuck do **YOU** think you are!?_.\n"\
"(You don't have the necessary role for this command)") "(You don't have the necessary role for this command)")
clock = comlock clock = comlock

@ -61,6 +61,14 @@ def migrate() -> None:
published_at date not null, published_at date not null,
index viewed_idx(title, published_at) index viewed_idx(title, published_at)
) character set utf8mb4 collate utf8mb4_general_ci; ) character set utf8mb4 collate utf8mb4_general_ci;
CREATE TABLE `ipm` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user` varchar(500) DEFAULT NULL,
`ipmlist` varchar(4096) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `user` (`user`) USING HASH
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
''' '''
try: try:
with Cursor(MYSQL_CONFIG) as cursor: with Cursor(MYSQL_CONFIG) as cursor:

@ -0,0 +1,24 @@
## IPM (Integrated Permissions Module)
# The Integrated Permissions Module will allow for individual sets of rules for individual users
import MySQLdb
from models.ipm import Ipm
from settings.config import MYSQL_CONFIG, SQLACHEMY
from sqlalchemy.orm import Session
import json
def ipm_check(user: str, ipmstring: str) -> bool:
ipmjson = {}
ipmstring = ipmstring.split('.')
with Session(SQLACHEMY) as session:
ipmlist = session.query(Ipm).filter(Ipm.user==user)
ipmlist = session.execute(ipmlist)
ipmlist = [obj.ipmlist for obj in ipmlist.scalars()]
ipmjson = json.loads(str(ipmlist[0])) if ipmlist else None
if ipmjson is None:
return False
if ipmstring[1] in ipmjson[ipmstring[0]] or "*" in ipmjson[ipmstring[0]]:
return True
else:
return False
Loading…
Cancel
Save