Discord¶
Main module¶
Discord related functionalities
-
sni.discord.discord.
complete_authentication_challenge
(discord_user: discord.user.User, code: str)[source]¶ Complete an authentication challenge, see
sni.discord.discord.new_authentication_challenge()
.
-
async
sni.discord.discord.
ensure_role_for_group
(grp: sni.user.models.Group)[source]¶ Ensure that a Discord role exists for the given group, and returns it.
-
sni.discord.discord.
new_authentication_challenge
(usr: sni.user.models.User) → str[source]¶ Creates a new authentication challenge.
The challenge proceeds as follows:
A user (
sni.user
) asks to start a challenge by calling this method.This methods returns a random code, and the user has 60 seconds type
!auth <code>
in the dedicated authentication channel.The Discord client is notified, and check this code against the pending Discort authentication challenges.
Discord bot¶
Discord Bot management. The bot requires the bot
scope, and the following
permissions:
* Manage Roles
* Change Nickname
* Manage Nicknames
* Send Messages
* Manage Messages
which corresponds to the the permission integer 469772288
. Therefore, the
invitation link for the bot should look like this: https://discord.com/api/oauth2/authorize?client_id=<bot_id>&permissions=469772288&scope=bot
.
.. seealso:: Discord developer portal, Creating a Bot Account
-
sni.discord.bot.
JOBS_KEY
: str = 'scheduler:discord:jobs'¶ The redis key for the job list
-
sni.discord.bot.
RUN_TIMES_KEY
: str = 'scheduler:discord:run_times'¶ The redis key for the job run times
-
sni.discord.bot.
get_guild
() → discord.guild.Guild[source]¶ Returns a guild handler corresponding to the
discord.server_id
setting.
-
sni.discord.bot.
get_member
(user_id: int) → discord.member.Member[source]¶ Gets a guild member by its user ID.
Discord bot commands¶
Discord bot commands
Discord bot events¶
Discord events
Database models¶
Database models
Jobs¶
Discord jobs.
These jobs run on a dedicated asyncio scheduler.
-
async
sni.discord.jobs.
update_discord_role
(grp: sni.user.models.Group)[source]¶ Updates a discord role. Makes sure all members of the group have that role, and demotes members that should not have it.
-
async
sni.discord.jobs.
update_discord_roles
()[source]¶ Updates discord role. A SNI group is mapped to a discord role unless that group’s
map_to_discord
ifFalse
Database signals¶
Database signals. See Mongoengine signals