Update and link new discord docs; reformat code for PEP8
This commit is contained in:
parent
45d52458e0
commit
c6e3ee7589
13 changed files with 66 additions and 18 deletions
|
|
@ -8,7 +8,6 @@ import time
|
|||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from evennia.accounts.accounts import DefaultAccount
|
||||
from evennia.scripts.scripts import DefaultScript
|
||||
from evennia.utils import logger, search, utils
|
||||
|
|
@ -566,8 +565,9 @@ class GrapevineBot(Bot):
|
|||
|
||||
class DiscordBot(Bot):
|
||||
"""
|
||||
Discord bot relay. You will need to set up your own bot (https://discord.com/developers/applications)
|
||||
and add the bot token as `DISCORD_BOT_TOKEN` to `secret_settings.py` to use
|
||||
Discord bot relay. You will need to set up your own bot
|
||||
(https://discord.com/developers/applications) and add the bot token as `DISCORD_BOT_TOKEN` to
|
||||
`secret_settings.py` to use
|
||||
"""
|
||||
|
||||
factory_path = "evennia.server.portal.discord.DiscordWebsocketServerFactory"
|
||||
|
|
@ -575,9 +575,11 @@ class DiscordBot(Bot):
|
|||
def at_init(self):
|
||||
"""
|
||||
Load required channels back into memory
|
||||
|
||||
"""
|
||||
if channel_links := self.db.channels:
|
||||
# this attribute contains a list of evennia<->discord links in the form of ("evennia_channel", "discord_chan_id")
|
||||
# this attribute contains a list of evennia<->discord links in the form
|
||||
# of ("evennia_channel", "discord_chan_id")
|
||||
# grab Evennia channels, cache and connect
|
||||
channel_set = {evchan for evchan, dcid in channel_links}
|
||||
self.ndb.ev_channels = {}
|
||||
|
|
@ -602,7 +604,8 @@ class DiscordBot(Bot):
|
|||
channel.connect(self)
|
||||
|
||||
elif channel_links := self.db.channels:
|
||||
# this attribute contains a list of evennia<->discord links in the form of ("evennia_channel", "discord_chan_id")
|
||||
# this attribute contains a list of evennia<->discord links in the form
|
||||
# of ("evennia_channel", "discord_chan_id")
|
||||
# grab Evennia channels, cache and connect
|
||||
channel_set = {evchan for evchan, dcid in channel_links}
|
||||
self.ndb.ev_channels = {}
|
||||
|
|
@ -627,6 +630,7 @@ class DiscordBot(Bot):
|
|||
Called by the Channel just before passing a message into `channel_msg`.
|
||||
|
||||
We overload this to set the channel tag prefix.
|
||||
|
||||
"""
|
||||
kwargs["no_prefix"] = not self.db.tag_channel
|
||||
return super().at_pre_channel_msg(message, channel, senders=senders, **kwargs)
|
||||
|
|
@ -663,7 +667,7 @@ class DiscordBot(Bot):
|
|||
sender (tuple) - The Discord info for the sender in the form (id, nickname)
|
||||
|
||||
Keyword args:
|
||||
kwargs (optional) - Unused by default, but can carry additional data from the protocol.
|
||||
**kwargs (optional) - Unused by default, but can carry additional data from the protocol.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
|
@ -672,17 +676,20 @@ class DiscordBot(Bot):
|
|||
self, message, to_channel, sender=None, from_channel=None, from_server=None, **kwargs
|
||||
):
|
||||
"""
|
||||
Formats and sends a Discord -> Evennia message. Called when the Discord bot receives a channel message on Discord.
|
||||
Formats and sends a Discord -> Evennia message. Called when the Discord bot receives a
|
||||
channel message on Discord.
|
||||
|
||||
Args:
|
||||
message (str) - Incoming text from Discord.
|
||||
to_channel (Channel) - The Evennia channel receiving the message
|
||||
|
||||
Keyword args:
|
||||
sender (tuple) - The Discord info for the sender in the form (id, nickname)
|
||||
sender (tuple) - The Discord info for the sender in the form `(id, nickname)`
|
||||
from_channel (str) - The Discord channel name
|
||||
from_server (str) - The Discord server name
|
||||
kwargs - Any additional keywords. Unused by default, but available for adding additional flags or parameters.
|
||||
kwargs - Any additional keywords. Unused by default, but available for adding additional
|
||||
flags or parameters.
|
||||
|
||||
"""
|
||||
|
||||
tag_str = ""
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import re
|
|||
from django.conf import settings
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Max, Min, Q
|
||||
|
||||
from evennia import InterruptCommand
|
||||
from evennia.commands.cmdhandler import get_and_merge_cmdsets
|
||||
from evennia.locks.lockhandler import LockException
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import re
|
|||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
from django.db.models.fields import exceptions
|
||||
|
||||
from evennia.server import signals
|
||||
from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager
|
||||
from evennia.utils.utils import (
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from collections import defaultdict
|
|||
import inflect
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from evennia.commands import cmdset
|
||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||
from evennia.objects.manager import ObjectManager
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ added to `server/conf/secret_settings.py` as your DISCORD_BOT_TOKEN
|
|||
"""
|
||||
import json
|
||||
import os
|
||||
from random import random
|
||||
from io import BytesIO
|
||||
from random import random
|
||||
|
||||
from autobahn.twisted.websocket import (
|
||||
WebSocketClientFactory,
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ SIGNAL_EXIT_TRAVERSED = Signal()
|
|||
|
||||
from django.core.signals import request_finished # " ends.
|
||||
from django.core.signals import request_started # Sent when HTTP request begins.
|
||||
from django.db.backends.signals import (
|
||||
from django.db.backends.signals import ( # Sent when making initial connection to database
|
||||
connection_created,
|
||||
) # Sent when making initial connection to database
|
||||
)
|
||||
from django.db.models.signals import m2m_changed # Sent when a ManyToManyField changes.
|
||||
from django.db.models.signals import post_delete # after "
|
||||
from django.db.models.signals import post_init # end
|
||||
|
|
@ -105,9 +105,15 @@ from django.db.models.signals import post_migrate # after "
|
|||
from django.db.models.signals import post_save # after "
|
||||
from django.db.models.signals import pre_delete # Sent before an object is deleted.
|
||||
from django.db.models.signals import pre_migrate # Sent before migration starts
|
||||
from django.db.models.signals import pre_save # Sent before a typeclass' .save is called.
|
||||
from django.db.models.signals import (
|
||||
pre_save, # Sent before a typeclass' .save is called.
|
||||
)
|
||||
from django.db.models.signals import ( # Sent at start of typeclass __init__ (before at_init)
|
||||
pre_init,
|
||||
) # Sent at start of typeclass __init__ (before at_init)
|
||||
from django.test.signals import setting_changed # Sent when setting changes from override
|
||||
from django.test.signals import template_rendered # Sent when test system renders template
|
||||
)
|
||||
from django.test.signals import (
|
||||
setting_changed, # Sent when setting changes from override
|
||||
)
|
||||
from django.test.signals import (
|
||||
template_rendered, # Sent when test system renders template
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import shlex
|
|||
|
||||
from django.db.models import Count, ExpressionWrapper, F, FloatField, Q
|
||||
from django.db.models.functions import Cast
|
||||
|
||||
from evennia.typeclasses.attributes import Attribute
|
||||
from evennia.typeclasses.tags import Tag
|
||||
from evennia.utils import idmapper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue