(config): Add emoji support.

This commit is contained in:
2022-01-20 08:40:44 +02:00
parent fa1d301cfb
commit 49c8ea5e02
3 changed files with 43 additions and 5 deletions

View File

@@ -1,8 +1,38 @@
from discord import PartialEmoji
import configparser as cfgp
from .args import args
class configEmoji(PartialEmoji):
__slots__ = ('fallback',)
def __init__(self, *args, fallback=None, **kwargs):
super().__init__(*args, **kwargs)
self.fallback = fallback
@classmethod
def from_str(cls, emojistr: str):
"""
Parses emoji strings of one of the following forms
`<a:name:id> or fallback`
`<:name:id> or fallback`
`<a:name:id>`
`<:name:id>`
"""
splits = emojistr.rsplit(' or ', maxsplit=1)
fallback = splits[1] if len(splits) > 1 else None
emojistr = splits[0].strip('<> ')
animated, name, id = emojistr.split(':')
return cls(
name=name,
fallback=PartialEmoji(name=fallback),
animated=bool(animated),
id=int(id)
)
class Conf:
def __init__(self, configfile, section_name="DEFAULT"):
self.configfile = configfile
@@ -11,6 +41,7 @@ class Conf:
converters={
"intlist": self._getintlist,
"list": self._getlist,
"emoji": configEmoji.from_str,
}
)
self.config.read(configfile)
@@ -20,6 +51,7 @@ class Conf:
self.default = self.config["DEFAULT"]
self.section = self.config[self.section_name]
self.bot = self.section
self.emojis = self.config['EMOJIS'] if 'EMOJIS' in self.config else self.section
# Config file recursion, read in configuration files specified in every "ALSO_READ" key.
more_to_read = self.section.getlist("ALSO_READ", [])

View File

@@ -1,9 +1,11 @@
import discord
import datetime
from meta.client import client
from bot.settings.setting_types import Integer
from meta import sharding
from meta import conf
from meta.client import client
from utils.lib import utc_now
from settings.setting_types import Integer
from modules.reminders.reminder import Reminder
from modules.reminders.data import reminders
@@ -17,8 +19,8 @@ remainder_content = (
"Click [here]({}) to vote, thank you for the support!"
).format(topgg_upvote_link)
lion_loveemote = '<:lionloveemote:933003977656795136>'
lion_yayemote = '<:lionyayemote:933003929229352990>'
lion_loveemote = conf.emojis.getemoji('lionlove')
lion_yayemote = conf.emojis.getemoji('lionyay')
def get_last_voted_timestamp(userid: Integer):

View File

@@ -17,4 +17,8 @@ lion_sync_period = 60
topgg_password =
topgg_route =
topgg_port =
topgg_port =
[EMOJIS]
lionyay =
lionlove =