Aller au contenu
Afficher dans l'application

Une meilleure façon de naviguer. En savoir plus.

Asterobot

Une application plein écran sur votre écran d'accueil avec notifications push, badges et plus encore.

Pour installer cette application sur iOS et iPadOS
  1. Appuyez sur Icône de partage dans Safari
  2. Faites défiler le menu et appuyez sur Ajouter à l'écran d'accueil.
  3. Appuyez sur Ajouter dans le coin supérieur droit.
Pour installer cette application sur Android
  1. Appuyez sur le menu à trois points (⋮) dans le coin supérieur droit du navigateur.
  2. Appuyez sur Ajouter à l'écran d'accueil ou Installer l'application.
  3. Confirmez en appuyant sur Installer.

Chat logger

(0 notes)

This script writes each chat line the bot receives to the bot's Console tab, as [GUILD] Airelle: anyone up for a dungeon?. It goes further than the handler in React to messages: package settings let people pause it, keep only the channels they choose and leave out some players, their own character included, and staff lines stand out as warnings.

The page assumes you've already created a package and run it on a bot. If you haven't, start with Create a package and Identify and run.

The script

  1. In Library Manager, click New package and name it chat-logger.
  2. Replace the contents of index.js with the code below, and save.
import { session, botInfo, botWarn } from "asterobot:bot";
import { values } from "asterobot:parameters";
import { on, send } from "asterobot:protocol";

/** @type {BehaviorParameters} */
export const parameters = {
  enabled: {
    type: "bool",
    label: "Log chat",
    default: true,
  },
  channels: {
    type: "array",
    of: "string",
    label: "Channels",
    description: "Channel names to log, such as GUILD or PARTY. Leave it empty to log every channel.",
  },
  ignored: {
    type: "array",
    of: "string",
    label: "Ignored characters",
    description: "Character names whose lines aren't logged. Add your own to leave out what you say.",
  },
};

export default async function behavior(launch) {
  on("ChatChannelMessageEvent", (traffic) => {
    // A message Asterobot couldn't decode has no payload, and an error
    // thrown in a handler stops the whole script.
    if (!traffic.payload || !values.enabled) return;

    const { senderName, content, fromAdmin } = traffic.payload;
    // A channel Asterobot has no name for reads as a number.
    const channel = String(traffic.payload.channel);

    // Read on every line, so an applied change counts from the next one.
    const channels = values.channels.map((name) => name.trim().toUpperCase());
    if (channels.length > 0 && !channels.includes(channel)) return;

    const sender = senderName.toLowerCase();
    if (values.ignored.some((name) => name.trim().toLowerCase() === sender)) return;

    const line = `[${channel}] ${senderName}: ${content}`;
    // Staff lines are rare and usually matter, so they show as warnings.
    if (fromAdmin) {
      botWarn(line);
    } else {
      botInfo(line);
    }
  });

  // A new game connection starts with this message. MITM bots never launch
  // with "initial": the Dofus client has already identified their session.
  if (launch.reason === "initial") {
    await send("IdentificationRequest", {
      ticketKey: session.gameToken,
      languageCode: session.language,
    });
  }
}

How it works

The settings

export const parameters declares three settings. They show on the bot's Settings tab, under Package settings, in the chat-logger section:

Setting Type On the bot's page Default
enabled bool Log chat, a switch On
channels array of string Channels, a list with Add under its rows Empty
ignored array of string Ignored characters, a list with Add under its rows Empty

A list can't offer a drop-down, because choices only works on string and int settings, so people type the names themselves. The script forgives the usual slips: it trims spaces, compares channel names in capitals, and ignores upper and lower case in character names. Declare settings covers every field used here.

Reading the settings on every line

The handler reads values.enabled, values.channels and values.ignored each time a chat line arrives. values always holds what was last applied on the bot's page, so a change counts from the next line, with no restart. That's also why turning Log chat off doesn't stop the script: the handler still runs for each line, and returns straight away. Read settings explains values.

The handler awaits nothing, so it needs no try/catch. The check at its top keeps it from reading a payload that isn't there.

Channel names

channel reads as the name of the channel the line was said on. The ones you'll use most:

Name Channel
GLOBAL The general channel, which the players around the character see
GUILD Guild
ALLIANCE Alliance
PARTY Party
TEAM Team
SALES Trade, where players advertise what they sell
SEEK Recruitment, to look for players or groups
COMMUNITY The community channel, split by language

The Dofus protocol reference lists every channel.

When Asterobot has no name for a channel's value, channel reads as that value's number instead of a name. String() turns it into text, so a number typed in Channels matches it like a name would.

Your own lines

The game sends your character's lines back to you like everyone else's, so the logger receives them too. session doesn't say which character the bot plays, so the plain way to leave your lines out is to put your character's name in Ignored characters. The same list works for any player you'd rather not read.

Staff lines

fromAdmin is true on lines the game marks as staff lines. The script writes those with botWarn() instead of botInfo(), so they show at the WARN level among the INFO lines.

Run it

Test it on a MITM bot (man-in-the-middle: the bot relays the game session of the Dofus client you play).

  1. Bring your MITM bot online and enter the game with your character, as Your first bot shows.
  2. In the editor, pick that bot and click Run. A toast says Running on followed by the bot's name.
  3. On the bot's page, open Console. In Sources, keep only Script.
  4. Say something in the Dofus chat. A line such as [GLOBAL] Airelle: hello appears.

Then try the settings:

  1. Open the bot's Settings tab, then Package settings.
  2. In the chat-logger section, click Add under Ignored characters and type your character's name. Not applied appears next to the package's name.
  3. Click Apply. A toast says chat-logger settings applied.
  4. Say something in the Dofus chat again. This time no line appears.
  5. Click Add under Channels, type GUILD and click Apply. From now on, only guild lines are logged.
  6. Turn off Log chat and click Apply. Nothing is logged any more, yet the bot's header still shows Stop: the script runs and waits for the switch to come back on.

The settings are saved with the bot, so they're still there the next time the script starts.

The script runs on a Full socket bot too, but chat only reaches a character that is in the game. This script identifies the bot and nothing more, so on a Full socket bot it needs a connection script that also chooses a character.

Ideas to take it further

  • Highlight some words. Add a keywords list setting, and write the lines that contain one of them with botWarn().
  • Ignore a person rather than a character. senderAccountId stays the same when a player switches characters. It's a 64-bit field, so it reads as a BigInt: compare it with BigInt values, as Payloads explains.
  • Count lines per channel. Keep the counts in a Map, and add a button that writes them to the console: see Declare actions.
  • Answer some lines. Send messages shows how to reply and check that the reply went through.

Next, the Inventory watcher follows kamas, pods and item quantities.

Commentaires des utilisateurs

Aucun avis à afficher.

Compte

Navigation

Recherche

Recherche

Configurer les notifications push du navigateur

Chrome (Android)
  1. Appuyez sur l'icône de cadenas à côté de la barre d'adresse.
  2. Tap Autorisations → Notifications.
  3. Ajustez vos préférences.
Chrome (Desktop)
  1. Cliquez sur l'icône représentant un cadenas dans la barre d'adresse..
  2. Select Paramètres du site.
  3. Find Notifications et ajustez vos préférences.