added command aliases for Reddit
This commit is contained in:
@@ -20,9 +20,8 @@ fetch_limit = 100
|
|||||||
search_flairs = ["Original Art"]
|
search_flairs = ["Original Art"]
|
||||||
|
|
||||||
# Command aliases for the Reddit bot, since those aren't autocomplete-able.
|
# Command aliases for the Reddit bot, since those aren't autocomplete-able.
|
||||||
# TODO: this
|
|
||||||
[reddit.aliases]
|
[reddit.aliases]
|
||||||
add_post = []
|
add_post = ["weekly_art", "weekly"]
|
||||||
|
|
||||||
|
|
||||||
[commands]
|
[commands]
|
||||||
|
|||||||
+4
-2
@@ -42,6 +42,7 @@ class Bot:
|
|||||||
self.data_f: TextIOWrapper | None = None
|
self.data_f: TextIOWrapper | None = None
|
||||||
self.data: dict[str, Any] = {}
|
self.data: dict[str, Any] = {}
|
||||||
self.flairs: list[str] = []
|
self.flairs: list[str] = []
|
||||||
|
self.aliases: dict[str, list[str]] = {}
|
||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
self.sr = await self.r.subreddit("+".join(self.sr_list))
|
self.sr = await self.r.subreddit("+".join(self.sr_list))
|
||||||
@@ -63,9 +64,10 @@ class Bot:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def update_cfg(self, new_cfg: dict[str, Any]) -> bool:
|
async def update_cfg(self, new_cfg: dict[str, Any]) -> bool:
|
||||||
self.sr_list = new_cfg[CFG_DATA_RE]["subreddits"].split("+")
|
|
||||||
self.sr = await self.r.subreddit("+".join(self.sr_list))
|
self.sr = await self.r.subreddit("+".join(self.sr_list))
|
||||||
|
self.sr_list = new_cfg[CFG_DATA_RE]["subreddits"].split("+")
|
||||||
self.fetch_limit = new_cfg[CFG_DATA_RE]["fetch_limit"]
|
self.fetch_limit = new_cfg[CFG_DATA_RE]["fetch_limit"]
|
||||||
self.flairs = new_cfg[CFG_DATA_RE]["search_flairs"]
|
self.flairs = new_cfg[CFG_DATA_RE]["search_flairs"]
|
||||||
|
self.aliases = new_cfg[CFG_DATA_RE]["aliases"]
|
||||||
init_lang(new_cfg["general"]["lang"])
|
init_lang(new_cfg["general"]["lang"])
|
||||||
return True
|
return True
|
||||||
@@ -11,7 +11,14 @@ async def make_cmd(cmd: str, bot: botPy.Bot) -> str:
|
|||||||
|
|
||||||
async def is_cmd(cmd: str, text: str, bot: botPy.Bot) -> bool:
|
async def is_cmd(cmd: str, text: str, bot: botPy.Bot) -> bool:
|
||||||
command: str = await make_cmd(cmd, bot)
|
command: str = await make_cmd(cmd, bot)
|
||||||
return command.lower() in text.lower()
|
|
||||||
|
if command.lower() in text.lower(): return True
|
||||||
|
|
||||||
|
for alias in bot.aliases[cmd]:
|
||||||
|
a_cmd = await make_cmd(alias, bot)
|
||||||
|
if a_cmd.lower() in text.lower(): return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def respond_to_mention(bot: botPy.Bot) -> bool:
|
async def respond_to_mention(bot: botPy.Bot) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user