public async Task StartAsync(CancellationToken cancellationToken) { this.Client.Log += async message => Console.WriteLine(message.Message); this.Client.MessageReceived += async message => { try { if (message.Author.Username == "ResistanceBot") { return; } var dm = await this.Client.GetDMChannelAsync(message.Channel.Id); if (message.Channel.Id != GameChannelId && dm == null) { return; } var move = MoveMessage.Interpret(message, this.GameService.Game); switch (move.Type) { case MoveMessage.MoveType.CrewDeclaration: await this.GameService.AcceptCrewAsync(move, this.Client); break; case MoveMessage.MoveType.MissionVote: await this.GameService.AcceptVote(move, this.Client); break; case MoveMessage.MoveType.ChatSpam: await this.GameService.SwearOnSpamAsync(move, this.Client); break; case MoveMessage.MoveType.TalkingToBot: await this.GameService.HumiliateAsync(move); break; default: throw new NotImplementedException("unknown message type"); } } catch (Exception ex) { Console.WriteLine(ex); } }; await this.Client.LoginAsync(TokenType.Bot, this.Configuration["BotToken"]); await this.Client.StartAsync(); }
public async Task AcceptCrewAsync(MoveMessage message, DiscordSocketClient client) { if (message.Raw.MentionedUsers.Select(u => u.Id).Distinct().Count() < message.Raw.MentionedUsers.Count) { await this.sendInGameChannelAsync("Брать одного игрока несколько раз для мудаков ;)", client); return; } this.Game.CurrentMission = new Mission <DiscordPlayer>(message.Raw.MentionedUsers.Select(u => new DiscordPlayer(u))); await this.Game.CurrentMission.StartAsync(); await this.sendInGameChannelAsync("Команда набрана!", client); }
public async Task AcceptVote(MoveMessage message, DiscordSocketClient client) { var vote = this.TryParse(message.Raw.Content); if (vote == null) { await message.Raw.Author.SendMessageAsync($"Читать научись! '{MoveMessage.Success}' или '{MoveMessage.Fail}', кусок говна!"); return; } await this.Game.CurrentMission.AcceptVoteAsync(vote.Value, message.Raw.Author.Id.ToString()); await this.sendInGameChannelAsync($"{message.Raw.Author.Username} проголосовал!", client); if (this.Game.CurrentMission.IsCompleted) { await this.sendInGameChannelAsync($"Миссия завершена. Провалов: {this.Game.CurrentMission.FailsCount}", client); } }
public async Task HumiliateAsync(MoveMessage message) { await message.Raw.Channel.SendMessageAsync("С ботом решил поговорить лол. Совсем друзей, чтоли нет? Хотя не важно, не отвечай, даже мне не интересно"); }
public async Task SwearOnSpamAsync(MoveMessage message, DiscordSocketClient client) { await this.sendInGameChannelAsync($"{message.Raw.Author.Username}, засунь себе в жопу своё '{message.Raw.Content}'. Здесь пишут только составы мисиий", client); }