// async with no await #pragma warning disable 1998 async Task HandleMessage(SocketMessage message) { if (!(message.Channel is IGuildChannel guildChannel)) { return; } if (!MudaeInfo.IsMudae(message.Author)) { return; } if (!_config.BotChannelIds.Contains(message.Channel.Id)) { return; } if (!TimersUpParser.TryParse(_client, message, out var state)) { return; } _states[guildChannel.GuildId] = state; Log.Debug($"Guild '{guildChannel.Guild}' state updated: {JsonConvert.SerializeObject(state)}"); }
async Task HandleReactionAsync(Cacheable <IUserMessage, ulong> cacheable, ISocketMessageChannel channel, SocketReaction reaction) { if (!_config.ClaimEnabled) { return; } if (!(channel is IGuildChannel guildChannel)) { return; } // channel must be enabled for claiming if (!_config.BotChannelIds.Contains(channel.Id)) { return; } // retrieve message if (!_messageCache.TryGetValue(reaction.MessageId, out var message)) { return; } // reactor must be mudae var user = reaction.User.IsSpecified ? reaction.User.Value : _client.GetUser(reaction.UserId); if (user == null || !MudaeInfo.IsMudae(user)) { return; } // reaction must be kakera if (!_kakeraMap.TryGetValue(reaction.Emote.Name, out var kakera)) { return; } // kakera must be configured to be claimed if (!_config.KakeraTargets.Contains(kakera)) { return; } // must have enough kakera power to claim this kakera var state = _state.Get(guildChannel.GuildId); if (!state.CanKakera) { return; } // claim kakera await Task.Delay(_config.KakeraClaimDelay); await message.AddReactionAsync(reaction.Emote); // update state state.KakeraPower -= state.KakeraConsumption; }
async Task HandleMessageAsync(SocketMessage message) { if (!(message is SocketUserMessage userMessage)) { return; } if (!MudaeInfo.IsMudae(message.Author)) { return; } if (!message.Embeds.Any()) { return; } // channel must be enabled for claiming if (!_config.BotChannelIds.Contains(message.Channel.Id)) { return; } // remember message _messageCache[message.Id] = userMessage; foreach (var m in _messageCache.Values) { if ((DateTimeOffset.Now - m.Timestamp).TotalMinutes >= 5) { _messageCache.TryRemove(m.Id, out _); } } }
async Task HandleMessageAsync(SocketMessage message) { if (!_config.ClaimEnabled) { return; } if (!(message is SocketUserMessage userMessage)) { return; } if (!MudaeInfo.IsMudae(message.Author)) { return; } // channel must be enabled for claiming if (!_config.BotChannelIds.Contains(message.Channel.Id)) { return; } try { await HandleMudaeMessageAsync(userMessage); } catch (Exception e) { Log.Warning($"Could not handle Mudae message {message.Id} '{message.Content}'.", e); } }