evennia.accounts.bots¶
Bots are a special child typeclasses of Account that are controlled by the server.
-
class
evennia.accounts.bots.
BotStarter
(*args, **kwargs)[源代码]¶ 基类:
evennia.scripts.scripts.DefaultScript
This non-repeating script has the sole purpose of kicking its bot into gear when it is initialized.
-
at_server_start
()[源代码]¶ This hook is called after the server has started. It can be used to add post-startup setup for Scripts without a timer component (for which at_start could be used).
-
at_repeat
()[源代码]¶ Called self.interval seconds to keep connection. We cannot use the IDLE command from inside the game since the system will not catch it (commands executed from the server side usually has no sessions). So we update the idle counter manually here instead. This keeps the bot getting hit by IDLE_TIMEOUT.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ 基类:
evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned
-
path
= 'evennia.accounts.bots.BotStarter'¶
-
typename
= 'BotStarter'¶
-
-
class
evennia.accounts.bots.
Bot
(*args, **kwargs)[源代码]¶ 基类:
evennia.accounts.accounts.DefaultAccount
A Bot will start itself when the server starts (it will generally not do so on a reload - that will be handled by the normal Portal session resync)
-
msg
(text=None, from_obj=None, session=None, options=None, **kwargs)[源代码]¶ Evennia -> outgoing protocol
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ 基类:
evennia.accounts.accounts.DefaultAccount.MultipleObjectsReturned
-
path
= 'evennia.accounts.bots.Bot'¶
-
typename
= 'Bot'¶
-
-
class
evennia.accounts.bots.
IRCBot
(*args, **kwargs)[源代码]¶ -
Bot for handling IRC connections.
-
factory_path
= 'evennia.server.portal.irc.IRCBotFactory'¶
-
start
(ev_channel=None, irc_botname=None, irc_channel=None, irc_network=None, irc_port=None, irc_ssl=None)[源代码]¶ Start by telling the portal to start a new session.
- 参数
ev_channel (str) – Key of the Evennia channel to connect to.
irc_botname (str) – Name of bot to connect to irc channel. If not set, use self.key.
irc_channel (str) – Name of channel on the form #channelname.
irc_network (str) – URL of the IRC network, like irc.freenode.net.
irc_port (str) – Port number of the irc network, like 6667.
irc_ssl (bool) – Indicates whether to use SSL connection.
-
get_nicklist
(caller)[源代码]¶ Retrive the nick list from the connected channel.
- 参数
caller (Object or Account) – The requester of the list. This will be stored and echoed to when the irc network replies with the requested info.
- Notes: Since the return is asynchronous, the caller is stored internally
in a list; all callers in this list will get the nick info once it returns (it is a custom OOB inputfunc option). The callback will not survive a reload (which should be fine, it’s very quick).
-
ping
(caller)[源代码]¶ Fire a ping to the IRC server.
- 参数
caller (Object or Account) – The requester of the ping.
-
reconnect
()[源代码]¶ Force a protocol-side reconnect of the client without having to destroy/recreate the bot “account”.
-
msg
(text=None, **kwargs)[源代码]¶ Takes text from connected channel (only).
- 参数
text (str, optional) – Incoming text from channel.
- 关键字参数
options (dict) – Options dict with the following allowed keys: - from_channel (str): dbid of a channel this text originated from. - from_obj (list): list of objects sending this text.
-
execute_cmd
(session=None, txt=None, **kwargs)[源代码]¶ Take incoming data and send it to connected channel. This is triggered by the bot_data_in Inputfunc.
- 参数
session (Session, optional) – Session responsible for this command. Note that this is the bot.
txt (str, optional) – Command string.
- 关键字参数
user (str) – The name of the user who sent the message.
channel (str) – The name of channel the message was sent to.
type (str) – Nature of message. Either ‘msg’, ‘action’, ‘nicklist’ or ‘ping’.
nicklist (list, optional) – Set if type=’nicklist’. This is a list of nicks returned by calling the self.get_nicklist. It must look for a list self._nicklist_callers which will contain all callers waiting for the nicklist.
timings (float, optional) – Set if type=’ping’. This is the return (in seconds) of a ping request triggered with self.ping. The return must look for a list self._ping_callers which will contain all callers waiting for the ping return.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
path
= 'evennia.accounts.bots.IRCBot'¶
-
typename
= 'IRCBot'¶
-
-
class
evennia.accounts.bots.
RSSBot
(*args, **kwargs)[源代码]¶ -
An RSS relayer. The RSS protocol itself runs a ticker to update its feed at regular intervals.
-
start
(ev_channel=None, rss_url=None, rss_rate=None)[源代码]¶ Start by telling the portal to start a new RSS session
- 参数
ev_channel (str) – Key of the Evennia channel to connect to.
rss_url (str) – Full URL to the RSS feed to subscribe to.
rss_rate (int) – How often for the feedreader to update.
- 引发
RuntimeError – If ev_channel does not exist.
-
execute_cmd
(txt=None, session=None, **kwargs)[源代码]¶ Take incoming data and send it to connected channel. This is triggered by the bot_data_in Inputfunc.
- 参数
session (Session, optional) – Session responsible for this command.
txt (str, optional) – Command string.
kwargs (dict, optional) – Additional Information passed from bot. Not used by the RSSbot by default.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
path
= 'evennia.accounts.bots.RSSBot'¶
-
typename
= 'RSSBot'¶
-
-
class
evennia.accounts.bots.
GrapevineBot
(*args, **kwargs)[源代码]¶ -
g Grapevine (https://grapevine.haus) relayer. The channel to connect to is the first name in the settings.GRAPEVINE_CHANNELS list.
-
factory_path
= 'evennia.server.portal.grapevine.RestartingWebsocketServerFactory'¶
-
start
(ev_channel=None, grapevine_channel=None)[源代码]¶ Start by telling the portal to connect to the grapevine network.
-
msg
(text=None, **kwargs)[源代码]¶ Takes text from connected channel (only).
- 参数
text (str, optional) – Incoming text from channel.
- 关键字参数
options (dict) – Options dict with the following allowed keys: - from_channel (str): dbid of a channel this text originated from. - from_obj (list): list of objects sending this text.
-
execute_cmd
(txt=None, session=None, event=None, grapevine_channel=None, sender=None, game=None, **kwargs)[源代码]¶ Take incoming data from protocol and send it to connected channel. This is triggered by the bot_data_in Inputfunc.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
path
= 'evennia.accounts.bots.GrapevineBot'¶
-
typename
= 'GrapevineBot'¶
-
-
class
evennia.accounts.bots.
DiscordBot
(*args, **kwargs)[源代码]¶ -
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'¶
-
at_pre_channel_msg
(message, channel, senders=None, **kwargs)[源代码]¶ Called by the Channel just before passing a message into channel_msg.
We overload this to set the channel tag prefix.
-
channel_msg
(message, channel, senders=None, relayed=False, **kwargs)[源代码]¶ Passes channel messages received on to discord
- 参数
message (str) –
channel (Channel) –
- 关键字参数
senders (list or None) - Object(s) –
relayed (bool) –
-
change_nickname
(new_nickname, guild_id, user_id, **kwargs)[源代码]¶ Changes a given user’s nickname on the given guild the bot is in.
- 参数
new_nickname (str) –
guild_id (int) –
user_id (int) –
-
assign_role
(role_id, guild_id, user_id, **kwargs)[源代码]¶ Assigns a user the role on the given guild the bot is in.
- 参数
role_id (int) –
guild_id (int) –
user_id (int) –
-
direct_msg
(message, sender, **kwargs)[源代码]¶ Called when the Discord bot receives a direct message on Discord.
- 参数
message (str) –
sender (tuple) - The Discord info for the sender in the form (id, nickname) –
- 关键字参数
**kwargs (optional) –
-
relay_to_channel
(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.
- 参数
message (str) –
to_channel (Channel) –
- 关键字参数
sender (tuple) - The Discord info for the sender in the form **(id, nickname) –
from_channel (str) –
from_server (str) –
- Any additional keywords. Unused by default, but available for adding additional (kwargs) – flags or parameters.
-
execute_cmd
(txt=None, session=None, type=None, sender=None, **kwargs)[源代码]¶ Take incoming data from protocol and send it to connected channel. This is triggered by the bot_data_in Inputfunc.
- 关键字参数
txt (str) –
session (Session) –
type (str, optional) – the protocol pre-processed it.
sender (tuple) – strings, in the form of (id, nickname)
- Any additional data specific to a particular type of actions. The data for (kwargs) – any Discord actions not pre-processed by the protocol will also be passed via kwargs.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶
-
path
= 'evennia.accounts.bots.DiscordBot'¶
-
typename
= 'DiscordBot'¶
-