From 027803a1467ead0b1ee708967217d65a07a6970d Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 13 Apr 2020 13:14:45 +0200 Subject: [PATCH] Misc #1736 --- .../ExamplePlugin.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs index 02b937380..f09b5e8d7 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Composition; +using System.Linq; using System.Threading.Tasks; using ArchiSteamFarm.Json; using ArchiSteamFarm.Plugins; @@ -140,6 +141,13 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin { public Task OnBotMessage(Bot bot, ulong steamID, string message) { // Normally ASF will expect from you async-capable responses, such as Task. This allows you to make your code fully asynchronous which is a core fundament on which ASF is built upon // Since in this method we're not doing any async stuff, instead of defining this method as async (pointless), we just need to wrap our responses in Task.FromResult<>() + + // As a starter, we can for example ignore messages sent from our own bots, since otherwise they can run into a possible infinite loop of answering themselves + if (Bot.BotsReadOnly.Values.Any(existingBot => existingBot.SteamID == steamID)) { + return Task.FromResult(null); + } + + // If this message doesn't come from one of our bots, we can reply to the user in some pre-defined way bot.ArchiLogger.LogGenericTrace("Hey boss, we got some unknown message here!"); return Task.FromResult("I didn't get that, did you mean to use a command?");