Run migrations! Added data migration for channel aliases

This commit is contained in:
Griatch 2021-05-14 23:05:59 +02:00
parent 51bef9bf97
commit 3218d74381
8 changed files with 72 additions and 31 deletions

View file

@ -51,6 +51,8 @@
- New FileHelpStorage system allows adding help entries via external files. - New FileHelpStorage system allows adding help entries via external files.
- In modules given by `settings.PROTOTYPE_MODULES`, spawner will now first look for a global - In modules given by `settings.PROTOTYPE_MODULES`, spawner will now first look for a global
list `PROTOTYPE_LIST` of dicts before loading all dicts in the module as prototypes. list `PROTOTYPE_LIST` of dicts before loading all dicts in the module as prototypes.
- New Channel-System using the `channel` command and nicks. Removed the `ChannelHandler` and the
concept of a dynamically created `ChannelCmdSet`.
### Evennia 0.9.5 (2019-2020) ### Evennia 0.9.5 (2019-2020)

View file

@ -170,7 +170,7 @@ The default `help` command has the following `locks` property:
locks = "cmd:not perm(channel_banned); admin:all(); manage:all(); changelocks: perm(Admin)" locks = "cmd:not perm(channel_banned); admin:all(); manage:all(); changelocks: perm(Admin)"
``` ```
This is a regular [lockstring](Locks). This is a regular [lockstring](./Locks).
- `cmd: pperm(channel_banned)` - The `cmd` locktype is the standard one used for all Commands. - `cmd: pperm(channel_banned)` - The `cmd` locktype is the standard one used for all Commands.
an accessing object failing this will not even know that the command exists. The `pperm()` lockfunc an accessing object failing this will not even know that the command exists. The `pperm()` lockfunc
@ -335,7 +335,7 @@ see the [Channel api docs](api:evennia.comms.comms.DefaultChannel) for details.
- `channel_prefix_string` - this property is a string to easily change how - `channel_prefix_string` - this property is a string to easily change how
the channel is prefixed. It takes the `channelname` format key. Default is `"[{channelname}] "` the channel is prefixed. It takes the `channelname` format key. Default is `"[{channelname}] "`
and produces output like `[public] ...``. and produces output like `[public] ...``.
- `subscriptions` - this is the [SubscriptionHandler](`api:evennia.comms.comms.SubscriptionHandler`), which - `subscriptions` - this is the [SubscriptionHandler](api:evennia.comms.comms#SubscriptionHandler), which
has methods `has`, `add`, `remove`, `all`, `clear` and also `online` (to get has methods `has`, `add`, `remove`, `all`, `clear` and also `online` (to get
only actually online channel-members). only actually online channel-members).
- `wholist`, `mutelist`, `banlist` are properties that return a list of subscribers, - `wholist`, `mutelist`, `banlist` are properties that return a list of subscribers,

View file

@ -66,7 +66,6 @@ in mind for your own game, this will give you a good start.
## Howto's ## Howto's
- [Giving Exits a default error](./Default-Exit-Errors) - [Giving Exits a default error](./Default-Exit-Errors)
- [Customize Channel output](./Customize-channels)
- [Add a command prompt](./Command-Prompt) - [Add a command prompt](./Command-Prompt)
- [Don't allow spamming commands](./Command-Cooldown) - [Don't allow spamming commands](./Command-Cooldown)
- [Commands that take time](./Command-Duration) - [Commands that take time](./Command-Duration)

View file

@ -91,7 +91,6 @@
- [Howto/Command Duration](Howto/Command-Duration) - [Howto/Command Duration](Howto/Command-Duration)
- [Howto/Command Prompt](Howto/Command-Prompt) - [Howto/Command Prompt](Howto/Command-Prompt)
- [Howto/Coordinates](Howto/Coordinates) - [Howto/Coordinates](Howto/Coordinates)
- [Howto/Customize channels](Howto/Customize-channels)
- [Howto/Default Exit Errors](Howto/Default-Exit-Errors) - [Howto/Default Exit Errors](Howto/Default-Exit-Errors)
- [Howto/Evennia for Diku Users](Howto/Evennia-for-Diku-Users) - [Howto/Evennia for Diku Users](Howto/Evennia-for-Diku-Users)
- [Howto/Evennia for MUSH Users](Howto/Evennia-for-MUSH-Users) - [Howto/Evennia for MUSH Users](Howto/Evennia-for-MUSH-Users)

View file

@ -74,7 +74,7 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
channel/lock channelname = lockstring channel/lock channelname = lockstring
channel/unlock channelname = lockstring channel/unlock channelname = lockstring
channel/ban channelname (list bans) channel/ban channelname (list bans)
channel/ban[/quiet] channelname[, channelname, ...] = subscribername [: logmessage] channel/ban[/quiet] channelname[, channelname, ...] = subscribername [: reason]
channel/unban[/quiet] channelname[, channelname, ...] = subscribername channel/unban[/quiet] channelname[, channelname, ...] = subscribername
channel/boot[/quiet] channelname[,channelname,...] = subscribername [: reason] channel/boot[/quiet] channelname[,channelname,...] = subscribername [: reason]
@ -161,7 +161,7 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
channel/unmute channelname channel/unmute channelname
Muting silences all output from the channel without actually Muting silences all output from the channel without actually
un-subscribing. Other channel members will see you are muted in the /who un-subscribing. Other channel members will see that you are muted in the /who
list. Sending a message to the channel will automatically unmute you. list. Sending a message to the channel will automatically unmute you.
## create and destroy ## create and destroy
@ -169,7 +169,9 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
Usage: channel/create channelname[;alias;alias[:typeclass]] [= description] Usage: channel/create channelname[;alias;alias[:typeclass]] [= description]
channel/destroy channelname [= reason] channel/destroy channelname [= reason]
Creates a new channel (or destroys one you control). Creates a new channel (or destroys one you control). You will automatically
join the channel you create and everyone will be kicked and loose all aliases
to a destroyed channel.
## lock and unlock ## lock and unlock
@ -193,28 +195,25 @@ class CmdChannel(COMMAND_DEFAULT_CLASS):
## boot and ban ## boot and ban
Usage: channel/ban channelname (list bans) Usage:
channel/ban channelname[, channelname, ...] = subscribername [: logmessage] channel/boot[/quiet] channelname[,channelname,...] = subscribername [: reason]
channel/ban channelname[, channelname, ...] = subscribername [: reason]
channel/unban channelname[, channelname, ...] = subscribername channel/unban channelname[, channelname, ...] = subscribername
channel/unban channelname channel/unban channelname
channel/boot[/quiet] channelname[,channelname,...] = subscribername [: reason] channel/ban channelname (list bans)
Booting will kick a named subscriber from a channel temporarily. It will Booting will kick a named subscriber from channel(s) temporarily. The
also remove all their aliases. They are still able to re-connect unless 'reason' will be passed to the booted user. Unless the /quiet switch is
they are also banned. The 'reason' given will be echoed to the user and used, the channel will also be informed of the action. A booted user is
channel. still able to re-connect, but they'll have to set up their aliases again.
Banning will block a given subscriber's ability to connect to a channel. It Banning will blacklist a user from (re)joining the provided channels. It
will not automatically boot them. The 'logmessage' will be stored on the will then proceed to boot them from those channels if they were connected.
channel and shown when you list your bans (so you can remember why they The 'reason' and `/quiet` works the same as for booting.
were banned).
So to permanently get rid of a user, the way to do so is to first ban them
and then boot them.
Example: Example:
ban mychannel1,mychannel2 = EvilUser : Was banned for spamming. boot mychannel1 = EvilUser : Kicking you to cool down a bit.
boot mychannel1,mychannel2 = EvilUser : No more spamming! ban mychannel1,mychannel2= EvilUser : Was banned for spamming.
""" """
key = "channel" key = "channel"

View file

@ -0,0 +1,41 @@
# Generated by Django 2.2.16 on 2021-05-14 20:32
from django.db import migrations
def migrate_channel_aliases(apps, schema_editor):
"""
Note - this migration uses the contemporary ChannelDB rather than
the apps.get_model version. This allows for using all the
helper functionality, but introduces a dependency on current code. So
We catch errors and warn, since this is not something that will be needed
after doing the first migration.
"""
from evennia.comms.models import ChannelDB
# ChannelDB = apps.get_model("comms", "ChannelDB")
for channel in ChannelDB.objects.all():
try:
chan_key = channel.db_key.lower()
channel_aliases = [chan_key] + [alias.lower() for alias in channel.aliases.all()]
for subscriber in channel.subscriptions.all():
nicktuples = subscriber.nicks.get(category="channel", return_tuple=True, return_list=True)
all_aliases = channel_aliases + [tup[2] for tup in nicktuples if tup[3].lower() == chan_key]
for key_or_alias in all_aliases:
channel.add_user_channel_alias(subscriber, key_or_alias)
except Exception as err:
# we want to continue gracefully here since this is a data-migration from
# an old to a new version and doesn't involve schema changes
print("channel-alias data migration 0019_auto_20210514_2032 skipped: {err}")
class Migration(migrations.Migration):
dependencies = [
('comms', '0018_auto_20191025_0831'),
]
operations = [
migrations.RunPython(migrate_channel_aliases)
]

View file

@ -1464,8 +1464,8 @@ class NickHandler(AttributeHandler):
shell patterns using the `fnmatch` library and can contain shell patterns using the `fnmatch` library and can contain
`$N`-markers to indicate the locations of arguments to catch. If `$N`-markers to indicate the locations of arguments to catch. If
`pattern_is_regex=True`, this must instead be a valid regular `pattern_is_regex=True`, this must instead be a valid regular
expression and the `$N`-markers must be named `argN` matching expression and the `$N`-markers must be named `argN` that matches
groups (see examples). numbered regex groups (see examples).
replacement (str): The string (or template) to replace `key` with replacement (str): The string (or template) to replace `key` with
(the "nickname"). This may contain `$N` markers to indicate where to (the "nickname"). This may contain `$N` markers to indicate where to
place the argument-matches place the argument-matches
@ -1487,7 +1487,7 @@ class NickHandler(AttributeHandler):
Example: Example:
- pattern (default shell syntax): `"gr $1 at $2"` - pattern (default shell syntax): `"gr $1 at $2"`
- pattern (with pattern_is_regex=True): `r"gr (?P<arg1>.+?) at (?P<arg2>.+?)" - pattern (with pattern_is_regex=True): `r"gr (?P<arg1>.+?) at (?P<arg2>.+?)"`
- replacement: `"emote With a flourish, $1 grins at $2."` - replacement: `"emote With a flourish, $1 grins at $2."`
""" """

View file

@ -1728,8 +1728,8 @@ def ask_yes_no(caller, prompt="Yes or No {options}?", yes_action="Yes", no_actio
If a string, this string will be echoed back to the caller. If a string, this string will be echoed back to the caller.
default (str optional): This is what the user will get if they just press the default (str optional): This is what the user will get if they just press the
return key without giving any input. One of 'N', 'Y', 'A' or `None` return key without giving any input. One of 'N', 'Y', 'A' or `None`
for no default (an explicit choice must be given). If 'A' is given, for no default (an explicit choice must be given). If 'A' (abort)
`allow_abort` kwarg is ignored and assumed set. is given, `allow_abort` kwarg is ignored and assumed set.
allow_abort (bool, optional): If set, the 'A(bort)' option is available allow_abort (bool, optional): If set, the 'A(bort)' option is available
(a third option meaning neither yes or no but just exits the prompt). (a third option meaning neither yes or no but just exits the prompt).
session (Session, optional): This allows to specify the session (Session, optional): This allows to specify the
@ -1737,10 +1737,11 @@ def ask_yes_no(caller, prompt="Yes or No {options}?", yes_action="Yes", no_actio
is an Account in multisession modes greater than 2. The session is is an Account in multisession modes greater than 2. The session is
then updated by the command and is available (for example in then updated by the command and is available (for example in
callbacks) through `caller.ndb._yes_no_question.session`. callbacks) through `caller.ndb._yes_no_question.session`.
*args, **kwargs: These are passed into the callables. *args: Additional arguments passed on into callables.
**kwargs: Additional keyword args passed on into callables.
Raises: Raises:
RuntimeError, FooError: If default and allow_abort clashes. RuntimeError, FooError: If default and `allow_abort` clashes.
Example: Example:
:: ::