ADD: Persistent quote stack.

pull/3/head
Kamal Curi 2 years ago
parent b526733b53
commit 068411ce1e

@ -20,6 +20,7 @@ You can also run neeble under [docker](https://www.docker.com/) with [docker-com
- Make sure you are running a SQL server instance - Make sure you are running a SQL server instance
- Create a database named `neeble` - Create a database named `neeble`
- Set up your environment variables with `environment/template` (You may copy the template into a new file) - Set up your environment variables with `environment/template` (You may copy the template into a new file)
- Make a file `/opt/neeble/id.stack` (or define your own with `NEEBLE_STACK_FILE`), it must contain an empty list (`[]`)
- Load environment variables with `source`: - Load environment variables with `source`:
`$ source environment/template` `$ source environment/template`

@ -5,7 +5,7 @@
█ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█ █ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█
█ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄ █ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄
█▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ █▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█
Neeble version: 2023.03.30 Neeble version: 2023.04.03
Bot source can be found by users with Bot source can be found by users with
the "Neeble Dev" role. the "Neeble Dev" role.
Thank you! Thank you!

@ -31,6 +31,9 @@ SQLACHEMY = create_engine(
# Define the log level # Define the log level
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper() LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
# Define the path for the quote ID stack file
QUOTE_STACK = os.environ.get('NEEBLE_STACK_FILE', '/opt/neeble/id.list')
# Logging custom config. # Logging custom config.
LOGGING_CONFIG = { LOGGING_CONFIG = {
'version': 1, 'version': 1,

@ -4,12 +4,13 @@ Bot commands.
import logging import logging
import os import os
import json
from random import choice from random import choice
from discord import Embed, Intents from discord import Embed, Intents
from discord.ext import commands from discord.ext import commands
from settings.config import IMAGE_TYPES, OW_API_CONFIG, PERMISSIONS from settings.config import IMAGE_TYPES, OW_API_CONFIG, PERMISSIONS, QUOTE_STACK
from utils.database import (count_quotes, count_quotes_user, get_by_id, get_quote_contains, from utils.database import (count_quotes, count_quotes_user, get_by_id, get_quote_contains,
get_quotes, remove_quote, set_quote) get_quotes, remove_quote, set_quote)
@ -21,8 +22,8 @@ from utils.weather import displayweather, getweatherdata
client = commands.Bot(command_prefix='--', intents=Intents.all()) client = commands.Bot(command_prefix='--', intents=Intents.all())
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
quote_id_stack = [] with open(QUOTE_STACK, mode='r') as f:
quote_id_stack = json.load(f)
@client.command(aliases=['q']) @client.command(aliases=['q'])
async def quote(bot: object, *quote: str) -> str: async def quote(bot: object, *quote: str) -> str:
@ -74,6 +75,10 @@ async def random_quote(bot: object) -> str:
if stack_len >= stack_limit: if stack_len >= stack_limit:
quote_id_stack.pop(0) quote_id_stack.pop(0)
# Writes to persistent stackfile
with open(QUOTE_STACK, mode='w') as f:
json.dump(quote_id_stack, f)
try: try:
# To image links. # To image links.

Loading…
Cancel
Save