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
- Create a database named `neeble`
- 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`:
`$ 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
the "Neeble Dev" role.
Thank you!

@ -31,6 +31,9 @@ SQLACHEMY = create_engine(
# Define the log level
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_CONFIG = {
'version': 1,

@ -4,12 +4,13 @@ Bot commands.
import logging
import os
import json
from random import choice
from discord import Embed, Intents
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,
get_quotes, remove_quote, set_quote)
@ -21,8 +22,8 @@ from utils.weather import displayweather, getweatherdata
client = commands.Bot(command_prefix='--', intents=Intents.all())
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'])
async def quote(bot: object, *quote: str) -> str:
@ -75,6 +76,10 @@ async def random_quote(bot: object) -> str:
if stack_len >= stack_limit:
quote_id_stack.pop(0)
# Writes to persistent stackfile
with open(QUOTE_STACK, mode='w') as f:
json.dump(quote_id_stack, f)
try:
# To image links.
if 'http' in chosen_one.quote:

Loading…
Cancel
Save