mirror of
https://github.com/hencaric/SCNewsBot.git
synced 2026-08-16 22:46:03 +01:00
add warning for legacy config
This commit is contained in:
@@ -9,12 +9,21 @@ class InvalidTokenException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidConfigException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
||||||
if not DISCORD_TOKEN:
|
if not DISCORD_TOKEN:
|
||||||
raise InvalidTokenException("A Discord token was not set.")
|
raise InvalidTokenException("A Discord token was not set.")
|
||||||
|
|
||||||
with open("config.toml", "rb") as config_file:
|
with open("config.toml", "rb") as config_file:
|
||||||
|
if "[permissions]" in config_file.read():
|
||||||
|
raise InvalidConfigException(
|
||||||
|
"The format for permissions has changed; please check the new example config."
|
||||||
|
)
|
||||||
|
|
||||||
config = Config(tomllib.load(config_file))
|
config = Config(tomllib.load(config_file))
|
||||||
|
|
||||||
bot = Bot(config)
|
bot = Bot(config)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class TemplatesCog(commands.Cog, name="Templates"):
|
|||||||
async def _list(self, ctx: commands.Context) -> None:
|
async def _list(self, ctx: commands.Context) -> None:
|
||||||
templates = "\n".join([f"- {template}" for template in self.templates])
|
templates = "\n".join([f"- {template}" for template in self.templates])
|
||||||
await ctx.reply(f"Here are all of the available templates: ```\n{templates}```")
|
await ctx.reply(f"Here are all of the available templates: ```\n{templates}```")
|
||||||
|
|
||||||
@commands.check(can_publish_announcements)
|
@commands.check(can_publish_announcements)
|
||||||
@templates.command()
|
@templates.command()
|
||||||
async def view(self, ctx: commands.Context, *, template_name: str) -> None:
|
async def view(self, ctx: commands.Context, *, template_name: str) -> None:
|
||||||
|
|||||||
@@ -34,9 +34,13 @@ class Config:
|
|||||||
return self._get_allowed_objects("allowed_users")
|
return self._get_allowed_objects("allowed_users")
|
||||||
|
|
||||||
def _get_allowed_objects(self, object_name, /) -> list:
|
def _get_allowed_objects(self, object_name, /) -> list:
|
||||||
allowed_objects = self.config["permissions"]["announcements"].get(object_name, [])
|
allowed_objects = self.config["permissions"]["announcements"].get(
|
||||||
|
object_name, []
|
||||||
|
)
|
||||||
if self.debug:
|
if self.debug:
|
||||||
allowed_objects += self.config["permissions"]["announcements"]["debug"].get(object_name, [])
|
allowed_objects += self.config["permissions"]["announcements"]["debug"].get(
|
||||||
|
object_name, []
|
||||||
|
)
|
||||||
|
|
||||||
return allowed_objects
|
return allowed_objects
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user