Beispiel #1
0
        public static async Task AddToQueueAsync(this SocketCommandContext Context, int code, string trainer, RequestSignificance sig, PK8 trade, PokeRoutineType routine, PokeTradeType type, SocketUser trader, string requestedIgn = "")
        {
            if ((uint)code > MaxTradeCode)
            {
                await Context.Channel.SendMessageAsync("Trade code should be 00000000-99999999!").ConfigureAwait(false);

                return;
            }

            IUserMessage test;

            try
            {
                const string helper = "I've added you to the queue! I'll message you here when your trade is starting.";
                test = await trader.SendMessageAsync(helper).ConfigureAwait(false);
            }
            catch (HttpException ex)
            {
                await Context.Channel.SendMessageAsync($"{ex.HttpCode}: {ex.Reason}!").ConfigureAwait(false);

                var noAccessMsg = Context.User == trader ? "You must enable private messages in order to be queued!" : "The mentioned user must enable private messages in order for them to be queued!";
                await Context.Channel.SendMessageAsync(noAccessMsg).ConfigureAwait(false);

                return;
            }

            // Try adding
            bool   result;
            string msg;

            if (requestedIgn != string.Empty)
            {
                result = Context.AddToTradeQueue(trade, code, trainer, sig, routine, type, trader, out msg, requestedIgn);
            }
            else
            {
                result = Context.AddToTradeQueue(trade, code, trainer, sig, routine, type, trader, out msg);
            }

            // Notify in channel
            await Context.Channel.SendMessageAsync(msg).ConfigureAwait(false);

            // Notify in PM to mirror what is said in the channel.
            await trader.SendMessageAsync(msg).ConfigureAwait(false);

            // Clean Up
            if (result)
            {
                // Delete the user's join message for privacy
                if (!Context.IsPrivate)
                {
                    await Context.Message.DeleteAsync(RequestOptions.Default).ConfigureAwait(false);
                }
            }
            else
            {
                // Delete our "I'm adding you!", and send the same message that we sent to the general channel.
                await test.DeleteAsync().ConfigureAwait(false);
            }
        }
        public async Task HandleJoined(SocketUser user, SocketVoiceChannel newChannel)
        {
            // Get user status
            var status = await GetDiscordUserStatus(user.Id);

            var synthbotUser = status != DiscordUserStatus.New || status != DiscordUserStatus.NoResponse
                                ? await _synthbotRestClient.GetUserFromDiscordIdAsync(user.Id.ToString())
                                : null;

            var playlist = await GetPlaylist(newChannel.Name);

            switch (status)
            {
            case DiscordUserStatus.New when _notificationsEnabled:
            {
                var uri = _spotifyInfoService.GetLoginUriAuto(user.Id.ToString(), user.Username);
                await user.SendMessageAsync(
                    $"Reply with \"@{_discord.CurrentUser.Username} notify\" to opt in to future notifications from me",
                    false,
                    EmbedFactory.Welcome.NewEmbed(user.Username, _discord.CurrentUser, uri));

                await _synthbotRestClient.SetDiscordUserStatus(user.Id.ToString(), DiscordUserStatus.NoResponse);

                return;
            }

            case DiscordUserStatus.RegisteredWithNotify when(synthbotUser?.AutoJoin ?? false):
            {
                await _synthbotRestClient.AddUserToChannel(newChannel.Name);

                if (_notificationsEnabled)
                {
                    await user.SendMessageAsync("", false, EmbedFactory.Notifications.AutoJoinNotify(_discord.CurrentUser, newChannel, playlist));
                }
                return;
            }

            case DiscordUserStatus.RegisteredWithNotify when(!synthbotUser?.AutoJoin ?? false) && _notificationsEnabled:
                await user.SendMessageAsync("", false, EmbedFactory.Notifications.Notify(_discord.CurrentUser, newChannel, playlist));

                break;

            case DiscordUserStatus.RegisteredWithoutNotify when synthbotUser?.AutoJoin ?? false:
                await _synthbotRestClient.AddUserToChannel(newChannel.Name);

                return;

            case DiscordUserStatus.RegisteredWithoutNotify:
            case DiscordUserStatus.NoResponse:
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
        }
Beispiel #3
0
        public async Task StartBanRouletteAsync(SocketCommandContext _context, IUserMessage _message)
        {
            //set the class variables
            context    = _context;
            botMessage = _message;

            //init userkicklist
            userToKick = new List <SocketGuildUser>();

            //add custom ReactionAddedEvent
            context.Client.ReactionAdded += BanRouletteReactionAdded;
            //wait one minute
            await Task.Delay(60000);

            //remove custom ReactionAddedEvent therefore ending the joining period
            context.Client.ReactionAdded -= BanRouletteReactionAdded;


            //Checks if enough users have joined
            if (userToKick.Count == 0)
            {
                await context.Channel.SendMessageAsync("Nobody joined the roulette :frowning:.  It has been cancelled.");
            }
            else
            {
                //gets a random user to kick
                Random          r    = new Random();
                SocketGuildUser user = userToKick[r.Next(0, userToKick.Count)];

                //this var will be used after the user is kicked
                //this is because the socketguilduser is destroyed in the kicking process
                SocketUser userDM = user;

                //try to send them a dm with invites back to the server
                try
                {
                    await userDM.SendMessageAsync("https://discord.gg/nDTZD56");

                    await userDM.SendMessageAsync("https://discord.gg/B2cKX22");

                    await context.Channel.SendMessageAsync(user.Mention + " has been kicked... What a loser!");

                    await user.KickAsync("You are not as lucky as you thought.", null);
                }
                //if it cant it will send a catch all message back to to the server explaining that it broke
                catch (HttpException)
                {
                    await context.Channel.SendMessageAsync("The person I attempted to kick is either a mod or didn't have their DMs turned on.");
                }
            }
        }
Beispiel #4
0
        public async Task Gotcha(SocketUser target = null)
        {
            try
            {
                target = target ?? Context.User;

                var    account       = UserAccounts.GetAccount(Context.User);
                var    targetAccount = UserAccounts.GetAccount(target);
                string unixT         = (Convert.ToString((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds));
                unixT = unixT.Remove(10, unixT.Length - 10);
                int userCooldown = account.GCooldown; if (Convert.ToInt32(unixT) - 600 > userCooldown || target == Context.User)
                {
                    if (targetAccount.GBlock.Equals(0))
                    {
                        await target.SendMessageAsync($"**{Context.User.Username}** Gotcha!");

                        await target.SendMessageAsync($"⠀⠀⠀⠀⠀⡼⡑⢅⠪⡐⠅⠪⡐⢌⠢⡑⠌⡢⢑⠌⠢⡑⠌⡢⠑⢌⠢⠑⡌⠰⡁⡣⢘⠵⢦⡀\n⠀⠀⠀⠀⢰⢍⠊⠔⠡⡈⠜⡠⠑⠄⢅⠌⡂⠢⡁⢊⠢⠘⢄⠊⢌⠂⢅⢑⢈⠢⡨⠠⡑⠨⠢⡫⡆\n⠀⠀⠀⠀⡗⢅⠑⡁⡑⠠⠊⡀⡑⠌⠐⠄⢊⠐⡨⠀⢅⠊⡠⠊⠠⠊⡠⠂⡁⠢⠐⡐⢈⠂⡑⢄⢙⢇⡀\n⠀⠀⠀⡸⡑⢌⠐⠄⢌⠐⡁⠔⢀⠊⡨⠠⢁⠢⢀⠑⠠⢂⠐⠌⡐⢁⠄⠌⠠⢁⠌⠠⠁⠔⢀⠢⢀⠣⢳⢄\n⠀⠀⢠⠫⡂⠔⢁⠂⠢⠐⡀⢊⠠⠂⡐⢐⠀⡂⢁⠈⠢⠠⡈⠄⠢⡀⢆⢨⢂⠔⡀⢅⠈⠂⠔⢀⠅⡐⢁⠫⣆\n⠀⢀⢏⠪⢀⠊⡠⠈⢄⠡⠐⡀⠢⢈⠠⠂⠨⢀⠂⡁⡊⣐⢄⣳⠕⠯⠚⠓⠛⠚⠶⣄⠅⡡⠈⢄⠐⠠⢁⠊⡜⣥⠀\n⠀⣜⠥⡑⠠⠂⡐⠈⠄⠄⡡⠠⢁⠂⠄⡑⠠⢁⢌⢔⢮⠎⠋⠁⠀⠀⠀⠀⠀⠀⠀⠑⢧⠐⡡⠠⢈⠂⢄⠡⡈⢮⡀\n⠰⣝⢆⠢⠁⠂⠌⠠⠑⡀⢂⠐⠄⡈⡐⢀⠑⢤⡳⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢙⡬⡀⠂⠔⢀⠢⠐⡈⢎⡇\n⢘⢮⡣⡂⠡⢁⠊⠠⠁⠔⢀⠁⠢⠐⡀⢅⠈⡲⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢷⡨⠨⡀⠅⢐⠈⠄⢪⢖\n⠈⡮⡳⡕⡡⢀⠊⠠⠑⠈⢄⠁⡊⢀⠢⠠⢈⠌⠳⡔⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢳⢕⢄⠑⢄⢈⠢⡁⢯⡂\n⠘⡮⡹⣖⠤⡁⢊⠠⠑⡀⠂⠔⢀⠂⠢⠠⢈⠂⠔⠠⡑⠝⢖⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠳⢝⣔⢦⡱⣜⠵⠃\n⠀⠸⡢⡊⡛⢼⢔⡄⡡⠠⢁⠌⠠⡈⢄⠁⠂⠌⠠⡁⠔⢈⠂⡙⢕⠢⠲⠪⡚⠪⠪⡋⢚⠕⡫⡲⡀⠀⠁⠈\n⠀⠀⠳⡨⢂⠡⠊⡱⠳⠶⣄⣊⠠⠂⠄⢊⠈⢄⠡⠐⡀⠅⡈⠄⢂⠁⡑⠄⠌⡐⠁⠌⠐⠄⡊⢨⡛⡄\n⠀⠀⠈⢕⠔⡀⠊⠠⡈⠢⡑⢍⡳⣳⢜⡤⣌⠠⢂⠂⠔⢀⠢⠈⠄⢂⠐⡈⠄⠨⡀⠅⠑⡠⢈⢆⡽⠁\n⠀⠀⠀⠨⢆⠌⡈⠐⠄⠡⠐⡡⢪⢗⢽⠆⠉⠙⠣⠷⣜⡤⡢⡡⡨⡀⡢⢐⢈⠔⡠⣊⢦⣪⠖⠏\n⠀ ⠀⠀⠀⠳⡨⡀⡑⢈⠂⡡⠐⢌⡷⣙⢖⣄⠀⠀⠀⠀⠈⠉⠙⠚⠚⠪⠳⠓⠋⠋⠁⠁\n⠀ ⠀⠀⠀⠈⢖⠄⠢⠐⠠⠂⢌⠠⢛⢮⡪⡜⣕⡀\n⠀⠀⠀⠀⠀⠀⠘⣎⢐⠡⢈⠂⠢⠐⡁⢝⢮⡪⡢⡹⣂\n⠀⠀⠀⠀⠀⠀⠀⠸⣢⠡⢂⢈⠐⡁⠔⠠⢓⢵⡪⢢⠑⡝⢢⣄\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠫⡢⠄⢌⢀⠊⡐⠡⢊⢷⡑⡌⡐⠡⡘⢦⡀\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⡔⢢⢀⠊⢄⠑⠔⡡⢻⡔⢌⠂⡕⡸⠆\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⡢⡡⡨⠠⡑⠌⡢⢑⠽⣪⡪⣢⠏\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢲⢐⠅⠢⡑⠨⡢⣙⢜\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢕⡕⡡⢊⠒⢔⢌⡗\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠕⡵⣩⡲⡕");

                        if (target != Context.User)
                        {
                            account.GCooldown = Convert.ToInt32(unixT);
                        }
                        var embed = new EmbedBuilder();
                        embed.WithTitle($":mailbox: **{target.Username}** you have a suprise waiting for you in dms!");
                        string fromUser = Convert.ToString(Context.User);
                        fromUser = fromUser.Remove(fromUser.Length - 5, 5);
                        embed.WithDescription($"from " + fromUser);
                        embed.WithColor(new Color(0, 255, 255));
                        embed.WithCurrentTimestamp();

                        await Context.Channel.SendMessageAsync("", false, embed.Build());
                    }
                    else
                    {
                        var embed = new EmbedBuilder();
                        embed.AddField(target.Username + "has blocked this command", "It's not my fault ur annoying!");
                        Context.Channel.SendMessageAsync("", false, embed.Build());
                    }
                }
                else
                {
                    await Context.Channel.SendMessageAsync("Still on cooldown. " + ((userCooldown - Convert.ToInt32(unixT)) + 600) + " seconds left");
                }
            }
            catch (Exception e)
            {
                Misc.ExceptionAlert(Context, e);
            }
        }
        public static async Task <bool> SendPartnerArtResponse(DiscordSocketClient client, Storage.UserData partnerData, SocketUser user, string monthTheme, bool notifyChannel = false)
        {
            if (string.IsNullOrWhiteSpace(partnerData.ArtUrl))
            {
                return(false);
            }

            string message = string.Format(Properties.Resources.REF_REVEAL_FINAL, user.Id, partnerData.UserName
                                           + (string.IsNullOrWhiteSpace(partnerData.NickName) ? "" : $" ({partnerData.NickName})"), monthTheme);

            Embed msg = Utils.EmbedMessage(client, message, Utils.Emotion.positive, partnerData.ArtUrl);

            await user.SendMessageAsync(embed : msg);

            if (notifyChannel)
            {
                SocketTextChannel channel = Utils.FindChannel(client, Storage.xs.Settings.GetWorkingChannel());
                if (channel == null)
                {
                    return(false);
                }

                await channel.SendMessageAsync(embed : msg);
            }

            return(true);
        }
Beispiel #6
0
        public async Task ResendJoinMessage(
            [Summary("The user who will receive the message. If left empty, this defaults to the command user.")]
            [Example("@InfiniBot#6309")]
            [Example("238279899687813120")]
            SocketUser user = null)
        {
            await Context.Message.DeleteAsync();

            if (user == null)
            {
                user = Context.User;
            }

            Embed embed = Data.GetJoinEmbed(Context.Guild);
            await user.SendMessageAsync(embed : embed);

            IMessage m = await ReplyAsync(
                embed : new EmbedBuilder()
                .WithTitle("Join Message Sent")
                .WithDescription($"I've PMed the join message to {user.Username}")
                .WithAutoDeletionFooter()
                .Build());

            await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000);

            await m.DeleteAsync();
        }
        private static async void CheckWeather_Elapsed(object sender, ElapsedEventArgs e)
        {
            foreach (User user in DatabaseAccess.Instance.Users)
            {
                if (user.NotifierTime == null || user.WeatherLocation == null)
                {
                    continue;
                }
                if (!(DateTime.Now.Hour == user.NotifierTime.Value.Hours && DateTime.Now.Minute == user.NotifierTime.Value.Minutes))
                {
                    continue;
                }
                SocketUser disUser = client.GetUser(user.Id);
                if (disUser == null)
                {
                    continue;
                }

                WeatherApi apiResult = await weatherApiHandler.Request2WeatherApiAsync(credentials.WeatherApiKey, user.WeatherLocation);

                EmbedBuilder weatherEmbed = new EmbedBuilder()
                                            .WithTitle("Weather Info")
                                            .WithDescription("Weather Notification for today")
                                            .AddField(user.WeatherLocation, $"{apiResult.Weather.Temperature} °C")
                                            .AddField("Max. Temp today", $"{apiResult.Weather.MaxTemperature} °C")
                                            .AddField("Min. Temp for today", $"{apiResult.Weather.MinTemperature} °C")
                                            .AddField("Weather Condition", apiResult.WeatherCondition.First().ShortDescription)
                                            .WithColor(Color.Blue)
                                            .WithTimestamp(DateTime.Now)
                                            .WithFooter(FileAccess.GENERIC_FOOTER, FileAccess.GENERIC_THUMBNAIL_URL);
                await disUser.SendMessageAsync(embed : weatherEmbed.Build()).ConfigureAwait(false);
            }
        }
Beispiel #8
0
        public async Task ProcessAsync(SocketMessage message)
        {
            int        verificationCode = Convert.ToInt32(message.Content);
            SocketUser messageAuthor    = message.Author;
            bool       isCodeCorrect    = this.verificationCodeManager.IsCodeCorrectForUser(verificationCode, messageAuthor.Id);

            if (isCodeCorrect == false)
            {
                NonBlockingLogger.Warn($"{messageAuthor.Username} provided a wrong verification code: {verificationCode}. Correct would have been: {this.verificationCodeManager.GetCodeForUser(messageAuthor.Id)}");
                await messageAuthor.SendMessageAsync(
                    "Hmmm... Es sieht aus, als wäre das der falsche Code. Bitte überprüfe, ob du mir den richtigen " +
                    "Code geschickt hast. Falls Ja, gib mir nochmals deine Mail Adresse, dann schicke ich dir ein neues Mail.\n\r" +
                    "Hmmm... It looks like that's the wrong code. Please make sure that you entered the code correctly. If you did, " +
                    "send me your mail address again and I'll send you another mail with a new verification code.");

                return;
            }

            SocketGuild     socketGuild     = messageAuthor.MutualGuilds.Single(sg => sg.CurrentUser != null && sg.CurrentUser.Guild.Id == sg.Id);
            SocketGuildUser socketGuildUser = socketGuild.Users.Single(sgu => sgu.Id == messageAuthor.Id);

            NonBlockingLogger.Info($"Verification code {verificationCode} is correct for user {messageAuthor.Username}");
            SocketRole socketRole = socketGuild.Roles.Single(sr => sr.Name == this.discordClient.StudentRoleName);
            await socketGuildUser.AddRoleAsync(socketRole);

            await socketGuildUser.SendMessageAsync("Danke vielmals. Du bist nun verifiziert als Student.\n\rThank you very much. You're now verified as a student.");

            NonBlockingLogger.Info($"Assigned role @student to {messageAuthor.Username}");
            this.verificationCodeManager.RemoveCodesForUser(messageAuthor.Id);
        }
Beispiel #9
0
        private async Task SendEmbedToBotOwner(ICommandContext context, IKey key)
        {
            SocketUser owner  = Client.GetUser(ConfigProperties.BotConfig.BotOwnerId);
            var        fields = new List <EmbedFieldBuilder>
            {
                new EmbedFieldBuilder
                {
                    IsInline = false,
                    Name     = "Key Properties",
                    Value    = $"Key: `{key.Key}`\nCreated by: `{owner}`\nExpires: " +
                               $"`{DateTime.Now.AddSeconds(key.LengthInSeconds).Humanize(false)}`"
                }
            };

            if (key.GetType() == typeof(PremiumKey))
            {
                var embed = new KaguyaEmbedBuilder
                {
                    Description = $"User `{context.User}` has just redeemed a " +
                                  $"Kaguya Premium key!",
                    Fields = fields
                };

                try
                {
                    await owner.SendMessageAsync(embed : embed.Build());
                }
                catch (HttpException)
                {
                    await ConsoleLogger.LogAsync("Attempted to DM an owner a notification about a " +
                                                 "Kaguya Premium key redemption, but a " +
                                                 "Discord.Net.HttpException was thrown.", LogLvl.WARN);
                }
            }
        }
Beispiel #10
0
        private async Task OnGuildMemberUpdated(SocketGuildUser BeforeGuildUser, SocketGuildUser AfterGuildUser)
        {
            User BeforeLocalUser = DatabaseHandler.GetFromDb(BeforeGuildUser);

            if (BeforeGuildUser.Username != AfterGuildUser.Username)
            {
                BeforeLocalUser.Username = AfterGuildUser.Username;
            }

            if (BeforeGuildUser.Nickname != BeforeGuildUser.Nickname)
            {
                BeforeLocalUser.Nickname = AfterGuildUser.Nickname;
            }

            if (BeforeGuildUser.GetAvatarUrl() != AfterGuildUser.GetAvatarUrl())
            {
                BeforeLocalUser.AvatarUrl = AfterGuildUser.GetAvatarUrl();
            }

            DatabaseHandler.Save();

            if (BeforeGuildUser.Status == UserStatus.Offline && AfterGuildUser.Status == UserStatus.Online)
            {
                List <Alert> Notifications =
                    DatabaseHandler.ListAllTargetAlerts(new Alert(), BeforeLocalUser);

                BeforeLocalUser.LastSeenOnline = DateTimeOffset.UtcNow;

                foreach (Alert n in Notifications)
                {
                    SocketUser NotificationAuthor = Client.GetUser(Convert.ToUInt64(n.User.Id));
                    await NotificationAuthor.SendMessageAsync($"Notification: {BeforeLocalUser.Username} is now online");
                }
            }
        }
Beispiel #11
0
        public async Task dm(SocketUser user, string msg)
        {
            string info = "Sedning " + user.Username + " " + msg + " . ";
            await user.SendMessageAsync(msg, false);

            await ReplyAsync(info);
        }
Beispiel #12
0
        public async Task BanUser(IGuildUser user, string reason = "No Reason Provided.")
        {
            try
            {
                SocketUser target        = null;
                var        mentionedUser = Context.Message.MentionedUsers.FirstOrDefault();
                target = mentionedUser ?? Context.User;

                var embed = new EmbedBuilder();
                embed.WithTitle($"You've been kicked by {Context.User.Username}!");
                embed.WithDescription($"Reason: {reason}");
                embed.WithColor(new Color(0, 255, 255));
                embed.WithCurrentTimestamp();

                await target.SendMessageAsync("", false, embed.Build());

                await Context.User.SendMessageAsync($"{target.Username} has been banned by {Context.User.Username}");

                await user.Guild.AddBanAsync(user, 5, reason);
            }
            catch (Exception e)
            {
                Misc.ExceptionAlert(Context, e);
            }
        }
        private static async void CheckWeather_Elapsed(object sender, ElapsedEventArgs e)
        {
            foreach (User user in DatabaseAccess.Instance.Users)
            {
                if (user.NotifierTime == null || user.WeatherLocation == null)
                {
                    continue;
                }
                if (!(DateTime.Now.Hour == user.NotifierTime.Value.Hours && DateTime.Now.Minute == user.NotifierTime.Value.Minutes))
                {
                    continue;
                }
                SocketUser disUser = client.GetUser(user.Id);
                if (disUser == null)
                {
                    continue;
                }

                dynamic temperature = JsonConvert.DeserializeObject <dynamic>(await ApiRequestService.Request2WeatherApiAsync(user.WeatherLocation));

                EmbedBuilder weatherEmbed = new EmbedBuilder()
                                            .WithTitle("Weather Info")
                                            .WithDescription("Weather Notification for today")
                                            .AddField(user.WeatherLocation, $"{temperature.main.temp} °C")
                                            .AddField("Max. Temp today", $"{temperature.main.temp_max} °C")
                                            .AddField("Min. Temp for today", $"{temperature.main.temp_min} °C")
                                            .AddField("Weather Condition", (string)temperature.weather[0].main)
                                            .WithColor(Color.Blue)
                                            .WithTimestamp(DateTime.Now)
                                            .WithFooter(FileAccess.GENERIC_FOOTER, FileAccess.GENERIC_THUMBNAIL_URL);
                await disUser.SendMessageAsync(embed : weatherEmbed.Build()).ConfigureAwait(false);
            }
        }
Beispiel #14
0
        //Allows for quick setup but generic responses
        private void SimpleHandelQuestions()
        {
            questionHandler.QuestionAwnsered += (s, e) =>
            {
                currentChannel.SendMessageAsync(e.awnser);
            };

            questionHandler.UnknownQuestion += (s, e) =>
            {
                currentChannel.SendMessageAsync(e.message);
            };

            //Optional: Set Frustrated Threshold To 0 to disable
            questionHandler.Frustrated += (s, e) =>
            {
                currentChannel.SendMessageAsync(e.awnser);
            };

            //Optional: When Insulted Will Respond With Random Insult
            questionHandler.Insulted += (s, e) =>
            {
                currentChannel.SendMessageAsync(e.awnser);
            };

            questionHandler.EncodedMessage += (s, e) =>
            {
                lastUser.SendMessageAsync($"Key: {e.key} -- Message: {e.message}");
            };
        }
        public async Task HandleMoved(SocketUser user, SocketVoiceChannel newChannel, SocketVoiceChannel oldChannel)
        {
            EmbedFieldBuilder previousPlaybackField = null;

            // Remove user from old channel's playback session
            await _synthbotRestClient.RemoveUserFromChannel(oldChannel.Name);

            // Get user status
            var status = await GetDiscordUserStatus(user.Id);

            if (status == DiscordUserStatus.RegisteredWithNotify)
            {
                var oldPlayback = await _synthbotRestClient.GetCurrentPlayback(oldChannel.Name);

                FullPlaylist oldPlaylist = null;
                if (oldPlayback != null)
                {
                    oldPlaylist = _spotifyInfoService.GetFullPlaylist(oldPlayback.SpotifyPlaylistId);
                }
                if (oldPlaylist != null)
                {
                    previousPlaybackField = EmbedFactory.Notifications.PreviousPlaybackField(oldChannel, oldPlaylist);
                }
            }

            var synthbotUser = await GetSynthbotUserIfExists(user.Id.ToString(), status);

            var playlist = await GetPlaylist(newChannel.Name);

            // Start playback on new channel if auto-join is on
            if (synthbotUser?.AutoJoin ?? false)
            {
                await _synthbotRestClient.AddUserToChannel(newChannel.Name);

                if (status == DiscordUserStatus.RegisteredWithNotify)
                {
                    await user.SendMessageAsync("", false, EmbedFactory.Notifications.AutoJoinNotify(_discord.CurrentUser, newChannel, playlist, previousPlaybackField));
                }
            }
            else
            {
                if (status == DiscordUserStatus.RegisteredWithNotify)
                {
                    await user.SendMessageAsync("", false, EmbedFactory.Notifications.Notify(_discord.CurrentUser, newChannel, playlist, previousPlaybackField));
                }
            }
        }
Beispiel #16
0
 public async Task dm(SocketUser user, [Remainder] string message)
 {
     if (!THONK.Core.Data.GuildValues.User.HasHigherRole((Context.User as SocketGuildUser), "Warlord"))
     {
         return;
     }
     await user.SendMessageAsync(message);
 }
Beispiel #17
0
        public async Task SendPMAsync(string message, SocketUser user)
        {
            string logmessage = String.Concat(user.Username, " was sent a messge");

            await Log(new LogMessage(LogSeverity.Info, "VERBOSE", logmessage));

            await user.SendMessageAsync(message);
        }
Beispiel #18
0
 public async Task <IUserMessage> ReplyToUserAsync(SocketUser target, EmbedBuilder embed)
 {
     if (!embed.Color.HasValue)
     {
         embed.WithColor(new Color(0x2C2F33));
     }
     return(await target.SendMessageAsync(embed : embed.Build()));
 }
Beispiel #19
0
 public async Task PrivateMessage(SocketUser target, [Remainder] string msg)
 {
     if (Context.User.Id != 333769079569776642)
     {
         return;
     }
     await target.SendMessageAsync(msg);
 }
Beispiel #20
0
        private async Task DoSubmit(SocketUser user, string time, string[] switches = null)
        {
            bool overwrite = false;

            if (switches?.Length > 0)
            {
                for (int i = 0; i < switches.Length; i++)
                {
                    switch (switches[i])
                    {
                    case "-o":
                        overwrite = true;
                        break;

                    default:
                        await user.SendMessageAsync("Unrecognized switches. Use hh:mm:ss");

                        break;
                    }
                }
            }

            var result = currentScore.TryAdd(user.Username, time, overwrite);

            switch (result)
            {
            case HighScoreAddResult.Ok:
                await commandListeningChannel.SendMessageAsync($"GG {user.Username}!");

                await highScoresChannel.SendMessageAsync(currentScore.ToStringWithRankings());

                break;

            case HighScoreAddResult.InvalidCommandString:
                await user.SendMessageAsync("Invalid time format. Use hh:mm:ss");

                break;

            case HighScoreAddResult.DuplicateEntryWithoutOverwrite:
                await user.SendMessageAsync("Duplicate entry. Use hh:mm:ss -o to overwrite old score.");

                break;

            default: break;
            }
        }
Beispiel #21
0
        public static Task ChallengeUser(SocketCommandContext ctx, SocketUser challengee)
        {
            async Task Do()
            {
                RemoveOldChallenges();

                SocketUser challenger = ctx.User;

                if (challenger.Id == challengee.Id || BattleContext.GetBattleContext(challenger) != null)
                {
                    return;
                }
                else if (BattleContext.GetBattleContext(challengee) != null)
                {
                    await PrintParticipating(challenger, challengee, ctx.Channel);
                }
                else
                {
                    Challenge c = GetChallenge(challenger);
                    if (c != null && c.Challenger.Id == challengee.Id)
                    {
                        await StartBattle(c);
                    }
                    else
                    {
                        c = GetChallenge(challengee);
                        if (c == null)
                        {
                            string msg = $"You were challenged to a Pokémon battle by {challenger.Mention}!\nThe challenge expires in {ChallengeMinuteExpiration} minutes.\nType `!accept` to accept the challenge.";
                            try
                            {
                                await challengee.SendMessageAsync(msg);
                            }
                            catch (Discord.Net.HttpException ex)
                            {
                                if (ex.DiscordCode == 50007)
                                {
                                    await ctx.Channel.SendMessageAsync($"{challenger.Mention} ― Cannot challenge {challengee.Mention} because their DMs are closed.");
                                }
                                Console.WriteLine("Challenge exception:{0}{1}", Environment.NewLine, ex);
                                return;
                            }
                            _challenges.Add(new Challenge(challenger, challengee, ctx.Guild));
                            await ctx.Channel.SendMessageAsync($"{challenger.Mention} ― Your challenge has been sent to {challengee.Username}.");
                        }
                        else
                        {
                            await ctx.Channel.SendMessageAsync($"{challenger.Mention} ― {challengee.Username} already has a pending challenge.");
                        }
                    }
                }
            }

            lock (_matchmakingLockObj)
            {
                return(Do());
            }
        }
Beispiel #22
0
        public async Task DestroyTrevorAsync(SocketUser user, int numberOfMessages)
        {
            while (numberOfMessages > 0)
            {
                await user.SendMessageAsync("get rekt");

                numberOfMessages--;
            }
        }
Beispiel #23
0
        public async Task Birthday(SocketUser user)
        {
            Program.Users.GetValueOrDefault(user.Id).currency = Program.Users.GetValueOrDefault(user.Id).currency + 100;
            await Program.SaveUser(user.Id);

            await user.SendMessageAsync("", false, Embed.GetEmbed($"**You've got mail!**", $"Happy Birthday {user.Username}!\nHave a great day!\nAs a birthday gift I have given you 100 Credits!"));

            await ReplyAsync($"**It's {user.Username}'s Birthday.**\nHappy Birthday to you!.\nHappy Birthday to you!.\nHappy Birthday dear {user.Username}!.\nHappy Birthday to you!.", true);
        }
Beispiel #24
0
        private async Task AnswerUserAndLogEmbed(SocketUser messageTarget, ISocketMessageChannel channel, Embed embed, SocketMessage message, bool anonymous = false)
        {
            var userMsg = await messageTarget.SendMessageAsync(embed : embed);

            await message.DeleteAsync();

            var channelMsg = await channel.SendMessageAsync(embed : embed);

            AddModMailMessage(channel.Id, channelMsg, userMsg, message.Author.Id, anonymous);
        }
        public static async Task <bool> PlayerExists(Player player, SocketUser user)
        {
            if (player == null)
            {
                await user.SendMessageAsync("You have not registered!");

                return(false);
            }
            return(true);
        }
        public static async Task <bool> AdventureExists(Adventure adventure, SocketUser user)
        {
            if (adventure == null)
            {
                await user.SendMessageAsync("Adventure does not exist!");

                return(false);
            }
            return(true);
        }
Beispiel #27
0
        public static async Task AddToQueueAsync(SocketCommandContext context, int code, string trainer, RequestSignificance sig, T trade, PokeRoutineType routine, PokeTradeType type, SocketUser trader, int catchID = 0)
        {
            if ((uint)code > MaxTradeCode)
            {
                await context.Channel.SendMessageAsync("Trade code should be 00000000-99999999!").ConfigureAwait(false);

                return;
            }

            try
            {
                const string helper = "I've added you to the queue! I'll message you here when your trade is starting.";
                IUserMessage test   = await trader.SendMessageAsync(helper).ConfigureAwait(false);

                // Try adding
                var result = AddToTradeQueue(context, trade, code, trainer, sig, routine, type, trader, out var msg, catchID);

                // Notify in channel
                await context.Channel.SendMessageAsync(msg).ConfigureAwait(false);

                // Notify in PM to mirror what is said in the channel.
                await trader.SendMessageAsync($"{msg}\nYour trade code will be **{code:0000 0000}**.").ConfigureAwait(false);

                // Clean Up
                if (result)
                {
                    // Delete the user's join message for privacy
                    if (!context.IsPrivate)
                    {
                        await context.Message.DeleteAsync(RequestOptions.Default).ConfigureAwait(false);
                    }
                }
                else
                {
                    // Delete our "I'm adding you!", and send the same message that we sent to the general channel.
                    await test.DeleteAsync().ConfigureAwait(false);
                }
            }
            catch (HttpException ex)
            {
                await HandleDiscordExceptionAsync(context, trader, ex).ConfigureAwait(false);
            }
        }
Beispiel #28
0
        public static async Task AddToQueueAsync(this SocketCommandContext Context, OrderRequest <Item> itemReq, string player, SocketUser trader)
        {
            IUserMessage test;

            try
            {
                const string helper = "I've added you to the queue! I'll message you here when your order is ready";
                test = await trader.SendMessageAsync(helper).ConfigureAwait(false);
            }
            catch (HttpException ex)
            {
                await Context.Channel.SendMessageAsync($"{ex.HttpCode}: {ex.Reason}!").ConfigureAwait(false);

                var noAccessMsg = Context.User == trader ? "You must enable private messages in order to be queued!" : $"{player} must enable private messages in order for them to be queued!";
                await Context.Channel.SendMessageAsync(noAccessMsg).ConfigureAwait(false);

                return;
            }

            // Try adding
            var result = AttemptAddToQueue(itemReq, trader.Mention, trader.Username, out var msg);

            // Notify in channel
            await Context.Channel.SendMessageAsync(msg).ConfigureAwait(false);

            // Notify in PM to mirror what is said in the channel.
            await trader.SendMessageAsync(msg).ConfigureAwait(false);

            // Clean Up
            if (result)
            {
                // Delete the user's join message for privacy
                if (!Context.IsPrivate)
                {
                    await Context.Message.DeleteAsync(RequestOptions.Default).ConfigureAwait(false);
                }
            }
            else
            {
                // Delete our "I'm adding you!", and send the same message that we sent to the general channel.
                await test.DeleteAsync().ConfigureAwait(false);
            }
        }
Beispiel #29
0
        private async Task _client_GuildMemberUpdated(SocketGuildUser beforeUser, SocketGuildUser afterUser)
        {
            if (beforeUser.Status == UserStatus.Offline &&
                afterUser.Status != UserStatus.Offline)
            {
                if ((afterUser.Id == 237170530157854732 || afterUser.Id == 310828842145284096))
                {
                    DataUtils.changeMode("xander");
                    ISocketMessageChannel sc = _client.GetGuild(GlobalVars.GUILD_ID).GetChannel(GlobalVars.CHANNEL_ID) as ISocketMessageChannel;
                    await sc.SendMessageAsync("Welcome back Xander! Mode set to Xander Mode!\nNote : You can always change mode with the **!mode** command :)");
                }

                //if ((afterUser.Id == 308305348643782656))
                //{
                //    ISocketMessageChannel sc = _client.GetGuild(GlobalVars.PRIVATE_GUILD_ID).GetChannel(GlobalVars.PRIVATE_CHANNEL_ID) as ISocketMessageChannel;
                //    await sc.SendMessageAsync("WB Adrian");
                //}
            }
            ISocketMessageChannel scz = _client.GetGuild(GlobalVars.PRIVATE_GUILD_ID).GetChannel(GlobalVars.PRIVATE_CHANNEL_ID) as ISocketMessageChannel;

            if (afterUser.Status == beforeUser.Status)
            {
                await scz.SendMessageAsync(afterUser + " " + beforeUser.Game + " -> " + afterUser.Game + " at " + DateTime.Now.ToLongTimeString());
            }
            else
            {
                await scz.SendMessageAsync(afterUser + " " + beforeUser.Status + " -> " + afterUser.Status + " at " + DateTime.Now.ToLongTimeString());
            }

            if (DataUtils.hasEmail(afterUser.ToString()))
            {
                SocketUser msc = _client.GetUser(DataUtils.getUserIDFromUsername(afterUser.ToString()));
                //RestDMChannel rdc = await msc.CreateDMChannelAsync();
                //await rdc.SendMessageAsync(pmmsg);
                await msc.SendMessageAsync("You have unread emails! Check them with !inbox");
            }


            //if (afterUser.Status == UserStatus.Invisible)
            //{
            //    ISocketMessageChannel sc = _client.GetGuild(GlobalVars.PRIVATE_GUILD_ID).GetChannel(GlobalVars.PRIVATE_CHANNEL_ID) as ISocketMessageChannel;
            //    await sc.SendMessageAsync("You can't hide from me!");
            //}
            //if (afterUser.Status == UserStatus.Offline)
            //{
            //    ISocketMessageChannel sc = _client.GetGuild(GlobalVars.PRIVATE_GUILD_ID).GetChannel(GlobalVars.PRIVATE_CHANNEL_ID) as ISocketMessageChannel;
            //    await sc.SendMessageAsync(afterUser.ToString() + " went offline!");
            //}

            //if (afterUser.Status == UserStatus.Online)
            //{
            //    ISocketMessageChannel sc = _client.GetGuild(GlobalVars.PRIVATE_GUILD_ID).GetChannel(GlobalVars.PRIVATE_CHANNEL_ID) as ISocketMessageChannel;
            //    await sc.SendMessageAsync(afterUser.ToString() + " came online!");
            //}
        }
Beispiel #30
0
 public async void DM(SocketUser target, string text)
 {
     try
     {
         await target.SendMessageAsync(text, true);
     }
     catch (Exception e)
     {
         nlog.LogError(e.ToString());
     }
 }