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( __table__ = Table(
"viewed_news", "viewed_news",
Base.metadata, Base.metadata,
autoload=True,
autoload_with=SQLACHEMY autoload_with=SQLACHEMY
) )

@ -11,5 +11,6 @@ class Quotes(Base):
__table__ = Table( __table__ = Table(
"neeble_quotes", "neeble_quotes",
Base.metadata, Base.metadata,
autoload=True,
autoload_with=SQLACHEMY 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 Help with the development of neeble-bot in
https://brejela.club/gitea/neeble-club/neeble https://brejela.club/gitea/neeble-club/neeble
Thank you! 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 # 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

@ -6,8 +6,6 @@ import os
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from time import sleep
from random import randrange from random import randrange
from discord import Embed, Intents from discord import Embed, Intents
@ -20,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())
@ -91,11 +90,6 @@ async def quote(bot: object, *quote: str) -> str:
if ex.args[0].find("Duplicate") != -1: if ex.args[0].find("Duplicate") != -1:
return await bot.send("There's already a quote from that same person, with that "\ return await bot.send("There's already a quote from that same person, with that "\
"exact match!") "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?_') return await bot.send(f'{ex.args}\n_What the fuck are you doing?_')
else: else:
global stack_limit global stack_limit
@ -144,12 +138,6 @@ async def random_quote(bot: object) -> str:
global last_rq global last_rq
global last_rqer global last_rqer
global rq_abusers 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) stack_len = len(quote_id_stack)
@ -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, 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) return await bot.send('**`Weather`**', embed=embed)
@ -694,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

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

Loading…
Cancel
Save