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
)

@ -11,5 +11,6 @@ class ViewedNews(Base):
__table__ = Table(
"viewed_news",
Base.metadata,
autoload=True,
autoload_with=SQLACHEMY
)

@ -11,5 +11,6 @@ class Quotes(Base):
__table__ = Table(
"neeble_quotes",
Base.metadata,
autoload=True,
autoload_with=SQLACHEMY
)

@ -5,7 +5,7 @@
█ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█
█ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄
█▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█
Neeble version: 2025.01.14
Neeble version: 2023.10.09d
Help with the development of neeble-bot in
https://brejela.club/gitea/neeble-club/neeble
Thank you!

@ -40,7 +40,7 @@ RQ_LEADERBOARD = os.environ.get('RQ_LEADERBOARD_FILE', '/opt/neeble/rqlb.list')
# Define the path for the --roulette leaderboard
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:
# Permissions are now granular, more than one distinct role
# can execute the commands, whatever roles are inside the

@ -6,8 +6,6 @@ import os
import json
from datetime import datetime, timedelta
from time import sleep
from random import randrange
from discord import Embed, Intents
@ -20,6 +18,7 @@ from utils.machine_monitor import Monitor
from utils.news_paper import News
from utils.tools import datetime_to_string, kbytes_to_gbytes
from utils.weather import displayweather, getweatherdata
from utils.ipm import ipm_check
client = commands.Bot(command_prefix='--', intents=Intents.all())
@ -91,11 +90,6 @@ async def quote(bot: object, *quote: str) -> str:
if ex.args[0].find("Duplicate") != -1:
return await bot.send("There's already a quote from that same person, with that "\
"exact match!")
elif ex.args[0].find("Lost") != -1:
await bot.send("SQL did an oopsie! Trying again...")
sleep(2)
qtid = set_quote(user, quote, date, "#nograb")
return await bot.send(f"Done: `{quote}\n` ID: `{qtid}`")
return await bot.send(f'{ex.args}\n_What the fuck are you doing?_')
else:
global stack_limit
@ -144,13 +138,7 @@ async def random_quote(bot: object) -> str:
global last_rq
global last_rqer
global rq_abusers
try:
chosen_one = get_quotes(quote_id_stack)
except Exception as ex:
if ex.args[0].find("Lost") != -1:
await bot.send("SQL did an oopsie! Trying again...")
sleep(2)
chosen_one = get_quotes(quote_id_stack)
chosen_one = get_quotes(quote_id_stack)
stack_len = len(quote_id_stack)
# The next two IF statements are meant to deal with `--rq` abuse
@ -436,8 +424,6 @@ async def weather(bot: object, *location: str) -> str:
value=f'{msg.wind_speed} m/s' if msg.wind_speed else default_msg,
)
embed.set_footer(text="Provided by Openweather.org")
return await bot.send('**`Weather`**', embed=embed)
@ -694,14 +680,16 @@ async def neeble_debug(bot:object) -> str:
Outputs debug data.
"""
# 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]
PermStatus = False
# # 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]
# 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 = True
PermStatus = ipm_check(bot.author.name, "mgmt.dbg")
if not PermStatus:
if PermStatus is False:
return await bot.send("_And who the fuck do **YOU** think you are!?_.\n"\
"(You don't have the necessary role for this command)")
clock = comlock

@ -61,6 +61,14 @@ def migrate() -> None:
published_at date not null,
index viewed_idx(title, published_at)
) 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:
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

@ -69,7 +69,7 @@ def displayweather(wdata) -> object:
case '10':
icon = ':white_sun_rain_cloud:'
case '11':
icon = ':thunder_cloud_rain:'
icon = ':thunder_cloud_lightning:'
case '13':
icon = ':snowflake:'
case '50':

Loading…
Cancel
Save