public async Task Start(IGuildUser user) { if (_phase == Phase.Started || _phase == Phase.Ended) { await _channel.SendErrorAsync(user.Mention + GetText("ttt_already_running")).ConfigureAwait(false); return; } else if (_users[0] == user) { await _channel.SendErrorAsync(user.Mention + GetText("ttt_against_yourself")).ConfigureAwait(false); return; } _users[1] = user; _phase = Phase.Started; _timeoutTimer = new Timer(async(_) => { await _moveLock.WaitAsync(); try { if (_phase == Phase.Ended) { return; } _phase = Phase.Ended; if (_users[1] != null) { _winner = _users[_curUserIndex ^= 1]; var del = _previousMessage?.DeleteAsync(); try { await _channel.EmbedAsync(GetEmbed(GetText("ttt_time_expired"))).ConfigureAwait(false); if (del != null) { await del.ConfigureAwait(false); } } catch { } } OnEnded?.Invoke(this); } catch { } finally { _moveLock.Release(); } }, null, _options.TurnTimer * 1000, Timeout.Infinite); _client.MessageReceived += Client_MessageReceived; _previousMessage = await _channel.EmbedAsync(GetEmbed(GetText("game_started"))).ConfigureAwait(false); }
public async Task Start(IGuildUser user) { if (_phase == Phase.Started || _phase == Phase.Ended) { await _channel.SendErrorAsync(user.Mention + " TicTacToe Game is already running in this channel.").ConfigureAwait(false); return; } else if (_users[0] == user) { await _channel.SendErrorAsync(user.Mention + " You can't play against yourself.").ConfigureAwait(false); return; } _users[1] = user; _log.Warn($"User {user} joined a TicTacToe game."); _phase = Phase.Started; timeoutTimer = new Timer(async(_) => { await moveLock.WaitAsync(); try { if (_phase == Phase.Ended) { return; } _phase = Phase.Ended; if (_users[1] != null) { _winner = _users[curUserIndex ^= 1]; var del = previousMessage?.DeleteAsync(); try { await _channel.EmbedAsync(GetEmbed("Time Expired!")).ConfigureAwait(false); await del.ConfigureAwait(false); } catch { } } OnEnded?.Invoke(this); } catch { } finally { moveLock.Release(); } }, null, 15000, Timeout.Infinite); NadekoBot.Client.MessageReceived += Client_MessageReceived; previousMessage = await _channel.EmbedAsync(GetEmbed("Game Started")).ConfigureAwait(false); }
private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) { username = username.ToLowerInvariant().Trim(); var fs = new FollowedStream { GuildId = channel.Guild.Id, ChannelId = channel.Id, Username = username, Type = type, }; IStreamResponse status; try { status = await _service.GetStreamStatus(fs).ConfigureAwait(false); } catch { await ReplyErrorLocalized("stream_not_exist").ConfigureAwait(false); return; } using (var uow = _db.UnitOfWork) { uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) .FollowedStreams .Add(fs); await uow.CompleteAsync().ConfigureAwait(false); } await channel.EmbedAsync(_service.GetEmbed(fs, status, Context.Guild.Id), GetText("stream_tracked")).ConfigureAwait(false); }
private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type) { username = username.ToLowerInvariant().Trim(); var fs = new FollowedStream { GuildId = channel.Guild.Id, ChannelId = channel.Id, Username = username, Type = type, }; StreamStatus status; try { status = await GetStreamStatus(fs).ConfigureAwait(false); } catch { await channel.SendErrorAsync("Stream probably doesn't exist.").ConfigureAwait(false); return; } using (var uow = DbHandler.UnitOfWork()) { uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) .FollowedStreams .Add(fs); await uow.CompleteAsync().ConfigureAwait(false); } await channel.EmbedAsync(fs.GetEmbed(status).Build(), $"🆗 I will notify this channel when status changes.").ConfigureAwait(false); }
public async Task Say(ITextChannel channel, [Leftover] string message) { if (string.IsNullOrWhiteSpace(message)) { return; } var rep = new ReplacementBuilder() .WithDefault(ctx.User, channel, (SocketGuild)ctx.Guild, (DiscordSocketClient)ctx.Client) .Build(); if (CREmbed.TryParse(message, out var embedData)) { rep.Replace(embedData); try { await channel.EmbedAsync(embedData.ToEmbed(), embedData.PlainText?.SanitizeMentions() ?? "").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } else { var msg = rep.Replace(message); if (!string.IsNullOrWhiteSpace(msg)) { await channel.SendConfirmAsync(msg).ConfigureAwait(false); } } }
public async Task Say(ITextChannel channel, [Leftover] string message) { if (string.IsNullOrWhiteSpace(message)) { return; } var rep = new ReplacementBuilder() .WithDefault(ctx.User, channel, (SocketGuild)ctx.Guild, (DiscordSocketClient)ctx.Client) .Build(); if (CREmbed.TryParse(message, out var embedData)) { rep.Replace(embedData); await channel.EmbedAsync(embedData, sanitizeAll : !((IGuildUser)Context.User).GuildPermissions.MentionEveryone).ConfigureAwait(false); } else { var msg = rep.Replace(message); if (!string.IsNullOrWhiteSpace(msg)) { await channel.SendConfirmAsync(msg).ConfigureAwait(false); } } }
public async Task StartEvent() { _msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize)).ConfigureAwait(false); await _client.SetGameAsync(_code).ConfigureAwait(false); _client.MessageDeleted += OnMessageDeleted; _client.MessageReceived += HandleMessage; _t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)); }
private async Task ByeUsers(GreetSettings conf, ITextChannel channel, IEnumerable <IUser> users) { if (!users.Any()) { return; } var rep = new ReplacementBuilder() .WithChannel(channel) .WithClient(_client) .WithServer(_client, (SocketGuild)channel.Guild) .WithManyUsers(users) .Build(); if (CREmbed.TryParse(conf.ChannelByeMessageText, out var embedData)) { rep.Replace(embedData); try { var toDelete = await channel.EmbedAsync(embedData).ConfigureAwait(false); if (conf.AutoDeleteByeMessagesTimer > 0) { toDelete.DeleteAfter(conf.AutoDeleteByeMessagesTimer); } } catch (Exception ex) { Log.Warning(ex, "Error embeding bye message"); } } else { var msg = rep.Replace(conf.ChannelByeMessageText); if (string.IsNullOrWhiteSpace(msg)) { return; } try { var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false); if (conf.AutoDeleteByeMessagesTimer > 0) { toDelete.DeleteAfter(conf.AutoDeleteByeMessagesTimer); } } catch (Exception ex) { Log.Warning(ex, "Error sending bye message"); } } }
public TicTacToe(ITextChannel channel, IGuildUser firstUser) { _channel = channel; _users = new IGuildUser[2] { firstUser, null }; _state = new int?[3, 3] { { null, null, null }, { null, null, null }, { null, null, null }, }; _log = LogManager.GetCurrentClassLogger(); _log.Warn($"User {firstUser} created a TicTacToe game."); _phase = Phase.Starting; moveLock = new SemaphoreSlim(1, 1); timeoutTimer = new Timer(async(_) => { await moveLock.WaitAsync(); try { if (_phase == Phase.Ended) { return; } _phase = Phase.Ended; if (_users[1] != null) { _winner = _users[curUserIndex ^= 1]; var del = previousMessage?.DeleteAsync(); try { await _channel.EmbedAsync(GetEmbed("Time Expired!")).ConfigureAwait(false); await del.ConfigureAwait(false); } catch { } } OnEnded?.Invoke(this); } catch { } finally { moveLock.Release(); } }, null, 15000, Timeout.Infinite); }
public async Task Start(IGuildUser user) { if (_phase == Phase.Started || _phase == Phase.Ended) { await _channel.SendErrorAsync(user.Mention + " TicTacToe Game is already running in this channel.").ConfigureAwait(false); return; } else if (_users[0] == user) { await _channel.SendErrorAsync(user.Mention + " You can't play against yourself.").ConfigureAwait(false); return; } _users[1] = user; _log.Warn($"User {user} joined a TicTacToe game."); _phase = Phase.Started; NadekoBot.Client.MessageReceived += Client_MessageReceived; previousMessage = await _channel.EmbedAsync(GetEmbed("Game Started")).ConfigureAwait(false); }
public async Task Run() { NadekoBot.Client.MessageReceived += PotentialAcro; var embed = GetEmbed(); //SUBMISSIONS PHASE await _channel.EmbedAsync(embed).ConfigureAwait(false); try { await Task.Delay(_time * 1000, _source.Token).ConfigureAwait(false); phase = AcroPhase.Idle; } catch (OperationCanceledException) { return; } //var i = 0; if (_submissions.Count == 0) { await _channel.SendErrorAsync(GetText("acrophobia"), GetText("acro_ended_no_sub")); return; } if (_submissions.Count == 1) { await _channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription( GetText("acro_winner_only", Format.Bold(_submissions.First().Value.ToString()))) .WithFooter(efb => efb.WithText(_submissions.First().Key.ToLowerInvariant().ToTitleCase()))) .ConfigureAwait(false); return; } var submissionClosedEmbed = GetEmbed(); await _channel.EmbedAsync(submissionClosedEmbed).ConfigureAwait(false); //VOTING PHASE phase = AcroPhase.Voting; try { //30 secondds for voting await Task.Delay(30000, _source.Token).ConfigureAwait(false); phase = AcroPhase.Idle; } catch (OperationCanceledException) { return; } await End().ConfigureAwait(false); }
public async Task Run() { NadekoBot.Client.MessageReceived += PotentialAcro; var embed = GetEmbed(); //SUBMISSIONS PHASE await channel.EmbedAsync(embed).ConfigureAwait(false); try { await Task.Delay(time * 1000, source.Token).ConfigureAwait(false); phase = AcroPhase.Idle; } catch (OperationCanceledException) { return; } //var i = 0; if (submissions.Count == 0) { await channel.SendErrorAsync("Acrophobia", "Game ended with no submissions."); return; } else if (submissions.Count == 1) { await channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription($"{submissions.First().Value.Mention} is the winner for being the only user who made a submission!") .WithFooter(efb => efb.WithText(submissions.First().Key.ToLowerInvariant().ToTitleCase()))) .ConfigureAwait(false); return; } var submissionClosedEmbed = GetEmbed(); await channel.EmbedAsync(submissionClosedEmbed).ConfigureAwait(false); //VOTING PHASE this.phase = AcroPhase.Voting; try { //30 secondds for voting await Task.Delay(30000, source.Token).ConfigureAwait(false); this.phase = AcroPhase.Idle; } catch (OperationCanceledException) { return; } await End().ConfigureAwait(false); }
public async Task StartEvent() { if (Emote.TryParse(_bc.BotConfig.CurrencySign, out var emote)) { _emote = emote; } else { _emote = new Emoji(_bc.BotConfig.CurrencySign); } _msg = await _channel.EmbedAsync(GetEmbed(_opts.PotSize)).ConfigureAwait(false); await _msg.AddReactionAsync(_emote).ConfigureAwait(false); _client.MessageDeleted += OnMessageDeleted; _client.ReactionAdded += HandleReaction; _t.Change(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)); }
public async Task CurrencyDropAmount(string str = null, [Remainder] ITextChannel channel = null) { channel = (ITextChannel)Context.Channel; var cmdname = "CurrencyDropAmount"; var sb = new StringBuilder(); float CurrentVal = NadekoBot.BotConfig.CurrencyDropAmount; if (string.IsNullOrWhiteSpace(str)) { sb.AppendLine($":information_source: **{cmdname}** is currently set to `{CurrentVal}`"); } else { int val = 0; if (int.TryParse(str, out val)) { if (val < 0) { sb.AppendLine($":anger: **{cmdname}** cannot accept values below `0`"); } else { if (val == CurrentVal) { sb.AppendLine($":information_source: **{cmdname}** is already set to `{CurrentVal}`"); } else { NadekoBot.BotConfig.CurrencyDropAmount = val; sb.AppendLine($":white_check_mark: **{cmdname}** has been changed from `{CurrentVal}` to `{val}`"); } } } else { sb.AppendLine($":anger: **{cmdname}** cannot accept text. Please input numbers instead."); } } await channel.EmbedAsync(new EmbedBuilder().WithColor(SettingColor).WithDescription(sb.ToString())).ConfigureAwait(false); }
private async Task LogVerboseError(CommandInfo cmd, ITextChannel channel, string reason) { if (channel == null || !guildsEnabled.Contains(channel.GuildId)) { return; } try { var embed = _hs.GetCommandHelp(cmd, channel.Guild) .WithTitle("Command Error") .WithDescription(reason) .WithErrorColor(); await channel.EmbedAsync(embed).ConfigureAwait(false); } catch { //ignore } }
private async Task LogVerboseError(CommandInfo cmd, ITextChannel channel, string reason) { if (channel == null) { return; } using var uow = _db.UnitOfWork; if (!uow.GuildConfigs.For(channel.GuildId).VerboseErrors) { return; } try { var embed = _hs.GetCommandHelp(cmd, channel.Guild) .WithTitle("Command Error") .WithDescription(reason) .WithErrorColor(); await channel.EmbedAsync(embed).ConfigureAwait(false); } catch { } }
public static async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) { if (voiceCh == null || voiceCh.Guild != textCh.Guild) { if (!silent) { await textCh.SendErrorAsync($"💢 You need to be in a voice channel on this server.").ConfigureAwait(false); } throw new ArgumentNullException(nameof(voiceCh)); } if (string.IsNullOrWhiteSpace(query) || query.Length < 3) { throw new ArgumentException("💢 Invalid query for queue song.", nameof(query)); } var musicPlayer = MusicPlayers.GetOrAdd(textCh.Guild.Id, server => { float vol = 1;// SpecificConfigurations.Default.Of(server.Id).DefaultMusicVolume; using (var uow = DbHandler.UnitOfWork()) { vol = uow.GuildConfigs.For(textCh.Guild.Id, set => set).DefaultMusicVolume; } var mp = new MusicPlayer(voiceCh, textCh, vol); IUserMessage playingMessage = null; IUserMessage lastFinishedMessage = null; mp.OnCompleted += async(s, song) => { try { lastFinishedMessage?.DeleteAfter(0); try { lastFinishedMessage = await mp.OutputTextChannel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo))) .ConfigureAwait(false); } catch { // ignored } if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.ProviderType == MusicType.Normal) { var relatedVideos = (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList(); if (relatedVideos.Count > 0) { await QueueSong(await queuer.Guild.GetCurrentUserAsync(), textCh, voiceCh, relatedVideos[new NadekoRandom().Next(0, relatedVideos.Count)], true).ConfigureAwait(false); } } } catch { } }; mp.OnStarted += async(player, song) => { try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { // ignored } var sender = player as MusicPlayer; if (sender == null) { return; } try { playingMessage?.DeleteAfter(0); playingMessage = await mp.OutputTextChannel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo))) .ConfigureAwait(false); } catch { } }; mp.OnPauseChanged += async(paused) => { try { IUserMessage msg; if (paused) { msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); } else { msg = await mp.OutputTextChannel.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); } msg?.DeleteAfter(10); } catch { } }; mp.SongRemoved += async(song, index) => { try { var embed = new EmbedBuilder() .WithAuthor(eab => eab.WithName("Removed song #" + (index + 1)).WithMusicIcon()) .WithDescription(song.PrettyName) .WithFooter(ef => ef.WithText(song.PrettyInfo)) .WithErrorColor(); await mp.OutputTextChannel.EmbedAsync(embed).ConfigureAwait(false); } catch { // ignored } }; return(mp); }); Song resolvedSong; try { musicPlayer.ThrowIfQueueFull(); resolvedSong = await SongHandler.ResolveSong(query, musicType).ConfigureAwait(false); if (resolvedSong == null) { throw new SongNotFoundException(); } musicPlayer.AddSong(resolvedSong, queuer.Username); } catch (PlaylistFullException) { try { await textCh.SendConfirmAsync($"🎵 Queue is full at **{musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}**."); } catch { } throw; } if (!silent) { try { //var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Queued Song #" + (musicPlayer.Playlist.Count + 1)).WithMusicIcon()) .WithDescription($"{resolvedSong.PrettyName}\nQueue ") .WithThumbnailUrl(resolvedSong.Thumbnail) .WithFooter(ef => ef.WithText(resolvedSong.PrettyProvider))) .ConfigureAwait(false); queuedMessage?.DeleteAfter(10); } catch { // ignored } // if queued message sending fails, don't attempt to delete it } }