예제 #1
0
        public async Task ProcessChannelAsync(string message)
        {
            bool channelFound = false;

            foreach (var channel in await _guild.GetTextChannelsAsync())
            {
                if (channel.Name.Equals(message))
                {
                    channelFound = true;
                    _channel     = channel;
                }
            }
            if (!channelFound)
            {
                await UserExtensions.SendMessageAsync(_user, $"No channel with the Name {message} found.");

                return;
            }
            await UserExtensions.SendMessageAsync(_user, $"Enter the date and time for raid run ({Constants.DateFormat}):");

            _state = State.date;
        }
예제 #2
0
        public override void OnCommand(List <string> stringParams, SocketUserMessage message)
        {
            if (message.MentionedUsers.Count == 0)
            {
                return;
            }


            SocketUser opponent = null;

            foreach (var user in message.MentionedUsers)
            {
                opponent = user;
                break;
            }

            if (message.Author.Id == opponent.Id)
            {
                return;
            }

            foreach (var challenges in gameData.Challenges)
            {
                if (challenges.ChallengerUser.Id == message.Author.Id || challenges.OpponentUser.Id == message.Author.Id)
                {
                    message.Channel.SendMessageAsync($"{message.Author.Username} you are currently busy in another challenge.");
                    return;
                }
                else if (challenges.ChallengerUser.Id == opponent.Id || challenges.OpponentUser.Id == opponent.Id)
                {
                    message.Channel.SendMessageAsync($"{opponent.Username} is currently busy in another challenge.");
                    return;
                }
            }
            gameData.CreateChallenge(message.Author, opponent, message.Channel);
            UserExtensions.SendMessageAsync(opponent, $"{message.Author.Username} has challenged you to a game of Rock, Paper, Scissors, Lizard, Spock. Please reply with either *decline* or *play x* where x is your move.");
        }
예제 #3
0
        private async void AddUser()
        {
            if (_raidService.AddUser(_raid.RaidId, _user, _role, _availability, _usedAccount, out string resultMessage))
            {
                try
                {
                    await UserExtensions.SendMessageAsync(_user, resultMessage);

                    IUserMessage userMessage = (IUserMessage)await _channel.GetMessageAsync(_raid.MessageId);

                    await userMessage.ModifyAsync(msg => msg.Embed = _raid.CreateRaidMessage());
                }
                catch { }
                finally
                {
                    _conversationService.CloseConversation(_user.Id);
                }
            }
            else
            {
                resultMessage += $"\n\n{CreateSignUpMessage(_raid)}";
                await UserExtensions.SendMessageAsync(_user, resultMessage);
            }
        }
예제 #4
0
        private async Task <bool> CreateRaid(string message)
        {
            StringReader strReader = new StringReader(message);

            if (!await SetTitleAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetChannelAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetDateAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetDurationAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetOrganisatorAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetGuildAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetVoiceChatAsync(strReader.ReadLine()))
            {
                return(false);
            }
            if (!await SetAccountTypeAsync(strReader.ReadLine()))
            {
                return(false);
            }


            string line = strReader.ReadLine();

            while (line != null && Parsers.TryParseRole(line, out int noPositions, out string roleName, out string roleDecription))
            {
                _raid.AddRole(noPositions, roleName, roleDecription);
                line = strReader.ReadLine();
            }
            if (_raid.Roles.Count == 0)
            {
                await UserExtensions.SendMessageAsync(_user, $"No role was found.");

                return(false);
            }

            string description = string.Empty;

            while (line != null)
            {
                if (!string.IsNullOrEmpty(description))
                {
                    description += "\n";
                }
                description += line;
                line         = strReader.ReadLine();
            }
            _raid.Description = description;
            return(true);
        }
        /// <summary>
        /// Handle an executed component
        /// Used for buttons, drop downs, etc.
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <returns></returns>
        private Task ComponentCommandExecuted(ComponentCommandInfo arg1, Discord.IInteractionContext arg2, Discord.Interactions.IResult arg3)
        {
            if (!arg3.IsSuccess)
            {
                // Defer if not already done:
                try
                {
                    arg2.Interaction.DeferAsync(true).GetAwaiter().GetResult();
                }
                catch
                {
                    // ignore
                }

                switch (arg3.Error)
                {
                case InteractionCommandError.UnmetPrecondition:
                    // Check for userperm error:
                    if (arg3.ErrorReason.Contains("UserPerm"))
                    {
                        arg2.Interaction.FollowupAsync("You do not have permission to execute this command.", ephemeral: true);
                        break;
                    }

                    arg2.Interaction.FollowupAsync("Action Failed\n" + arg3.ErrorReason, ephemeral: true);
                    break;

                case InteractionCommandError.UnknownCommand:
                    arg2.Interaction.FollowupAsync("Unknown action. It may have been recently removed or changed.", ephemeral: true);
                    break;

                case InteractionCommandError.BadArgs:
                    arg2.Interaction.FollowupAsync("The provided values are invalid. (BadArgs)", ephemeral: true);
                    break;

                case InteractionCommandError.Exception:
                    //notify owner if desired:
                    if (arg3.ErrorReason.Contains("Invalid Form Body"))
                    {
                        arg2.Interaction.FollowupAsync("Invalid form body. Please check to ensure that all of your parameters are correct.", ephemeral: true);
                        break;
                    }
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...", ephemeral: true);
                    break;

                case InteractionCommandError.Unsuccessful:
                    //notify owner if desired:
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...", ephemeral: true);
                    break;

                default:
                    //notify owner if desired:
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...");
                    break;
                }
            }

            return(Task.CompletedTask);
        }
예제 #6
0
        public async Task Activate_account(string Activator, ICommandContext context)     //create activation request
        {
            DocumentReference docRef   = db.Collection("activators").Document(Activator); // find activator
            DocumentSnapshot  snapshot = await docRef.GetSnapshotAsync();                 // get snaphot of it

            IUser author = context.Message.Author;                                        // gets author of dicord command

            if (snapshot.Exists)                                                          // check existence
            {
                Dictionary <string, object> load = snapshot.ToDictionary();               //convert snapshot to dictionary pairs
                foreach (KeyValuePair <string, object> pair in load)                      //
                {
                    if (pair.Key == "author")                                             // i know there are better and safer ways, but I'm not experienced developer, and it works fine, so who cares :)
                    {
                        if (pair.Value.ToString() == context.Message.Author.Username)     // check if sender is koo of team -- security issue - people can change their discord name
                        {
                            // gets team with that activator - again not safe beware more teams with one activator - that can happen
                            Query         pas      = db.Collection("Team").WhereEqualTo("ACT_Id", Convert.ToInt32(Activator));
                            QuerySnapshot pas_snap = await pas.GetSnapshotAsync();

                            Team  team;
                            IUser user = context.User;
                            foreach (DocumentSnapshot doc in pas_snap.Documents)
                            {
                                team = doc.ConvertTo <Team>();
                                if (team.User == context.Message.Author.Username) // check if it is right team -- trying to fix security issue from line 53
                                {
                                    IRole grole;
                                    await UserExtensions.SendMessageAsync(author, "Tvoje heslo je: " + doc.Id); // sends password of team

                                    if (team.Game == "LoL")
                                    {
                                        grole = context.Guild.Roles.FirstOrDefault(x => x.Id.ToString() == "804414960289054770");
                                    }
                                    else
                                    {
                                        grole = context.Guild.Roles.FirstOrDefault(x => x.Id.ToString() == "804414757482397797");
                                    }
                                    await(user as IGuildUser).AddRoleAsync(grole);  //asign game role to user
                                }
                            }
                            var role = context.Guild.Roles.FirstOrDefault(x => x.Id.ToString() == "804672968424030268"); // get koo role
                            await(user as IGuildUser).AddRoleAsync(role);                                                //asign koo role to user
                            await docRef.DeleteAsync();                                                                  // delete activator object in database - on start all teams with existing activator will be removed

                            await context.Channel.SendMessageAsync("A je to, do soukromých zpráv jsme ti poslali heslo, kterým se můžes přihlásit na našich stránkách, děkujeme ti za registraci v Skautském herním klání");
                        }
                        else
                        {
                            Console.WriteLine(pair.Value + " a " + author.Username + " doesn't match"); // in case of bad user requests
                            await context.Channel.SendMessageAsync("jméno člověka, který registroval tým, se s tvým neschoduje, aktivační příkaz musí poslat koordinátor týmu");
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Document {0} does not exist!", snapshot.Id);
                await context.Channel.SendMessageAsync("tento aktivační kód buď neexistuje, nebo už byl použit"); // in case of nonexisting activation number
            }
        }
예제 #7
0
        public async Task HandleReaction(SocketReaction reaction, IGuildUser user, ulong guildId, string raidId)
        {
            if (!Raids.ContainsKey(raidId))
            {
                return;
            }

            Raid         raid        = Raids[raidId];
            IUserMessage userMessage = (IUserMessage)await reaction.Channel.GetMessageAsync(raid.MessageId);

            IEmote emote = reaction.Emote;

            if (emote.Equals(Constants.SignOffEmoji))
            {
                RemoveUser(raid.RaidId, user.Id);
                SaveRaids();
                await userMessage.ModifyAsync(msg => msg.Embed = raid.CreateRaidMessage());

                await userMessage.RemoveReactionAsync(reaction.Emote, user);

                return;
            }

            ulong userId = user.Id;

            if (_userService.GetAccounts(guildId, userId, raid.AccountType).Count == 0)
            {
                await UserExtensions.SendMessageAsync(user, $"No Account found, please add an Account with \"!user add {raid.AccountType} <AccountName>\".\n" +
                                                      "\n**This command only works on a server.**");

                return;
            }

            if (emote.Equals(Constants.FlexEmoji))
            {
                if (!_conversationService.UserHasConversation(user.Id))
                {
                    _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Flex);
                }
            }
            else if (raid.Users.ContainsKey(userId))
            {
                if (emote.Equals(Constants.SignOnEmoji))
                {
                    if (raid.IsAvailabilityChangeAllowed(userId, Constants.Availability.Yes))
                    {
                        raid.Users[userId].Availability = Constants.Availability.Yes;
                    }
                }
                else if (emote.Equals(Constants.UnsureEmoji))
                {
                    raid.Users[userId].Availability = Constants.Availability.Maybe;
                }
                else if (emote.Equals(Constants.BackupEmoji))
                {
                    raid.Users[userId].Availability = Constants.Availability.Backup;
                }
            }
            else if (!_conversationService.UserHasConversation(user.Id))
            {
                if (emote.Equals(Constants.SignOnEmoji))
                {
                    _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Yes);
                }
                else if (emote.Equals(Constants.UnsureEmoji))
                {
                    _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Maybe);
                }
                else if (emote.Equals(Constants.BackupEmoji))
                {
                    _conversationService.OpenSignUpConversation(this, reaction, user, raid, Constants.Availability.Backup);
                }
            }
            SaveRaids();
            await userMessage.ModifyAsync(msg => msg.Embed = raid.CreateRaidMessage());

            await userMessage.RemoveReactionAsync(reaction.Emote, user);
        }
예제 #8
0
 private async Task <IUserMessage> FailReply(string msg) => await UserExtensions.SendMessageAsync(Context.User, $":negative_squared_cross_mark: {msg}");
예제 #9
0
        private async Task OnReactionadd(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel ch, SocketReaction reac)
        {
            Account acc = Global.AccountList.Find(a => a.DiscordID == reac.UserId);

            if (!(acc == null))
            {
                if (Global.MsgGrade.ContainsKey(reac.MessageId))
                {
                    var   key  = reac.MessageId;
                    Grade grde = Global.MsgGrade[key];

                    if (grde.obs == null)
                    {
                        if (!reac.Emote.Name.Equals("❌"))
                        {
                            grde.atv = Global.AtvsEmojis[reac.Emote.Name];
                            Global.MsgGrade.Remove(key);
                            EmbedBuilder embed = new EmbedBuilder();
                            embed.WithColor(40, 200, 150);
                            embed.WithTitle("Algo a declarar?");
                            embed.WithDescription("Adicione Observações em sua Grade!\n Me envie uma mensagem com as observações que deseja adicionar a grade, se não quiser nenhuma envie **0**\n Lembre-se de mencionar armas, Poder e outros atributos que considera importante para o sucesso da missão!");
                            RestUserMessage x = await ch.SendMessageAsync("", false, embed.Build());

                            Global.MsgGrade.Add(x.Id, grde);
                            acc.EstadodeAcao = Flag.escrevendo;
                            acc.lastmsg      = x.Id;
                            grde.Msg         = x.Id;
                        }
                        else
                        {
                            grde.stat = Status.Cancelada;
                            EmbedBuilder embed = new EmbedBuilder();
                            embed.WithColor(250, 0, 0);
                            embed.WithTitle("Grade Cancelada");

                            RestUserMessage x = await ch.SendMessageAsync("", false, embed.Build());
                        }
                    }
                    else if (grde.MaxMembers != 0)

                    {
                        Grade g = Global.MsgGrade[reac.MessageId];
                        if (reac.Emote.Name.Equals("❌"))
                        {
                            if (g.Principais.Find(a => a.DiscordID == acc.DiscordID) != null)
                            {
                                if (acc.DiscordID == g.Organizador.DiscordID)
                                {
                                    g.Organizador.EstadodeAcao = Flag.deletando_grade;
                                    acc.EstadodeAcao           = Flag.deletando_grade;
                                    g.stat = Status.Cancelada;
                                    EmbedBuilder embed = new EmbedBuilder();
                                    embed.WithColor(250, 0, 0);
                                    embed.WithTitle("Está desistindo??");
                                    embed.WithDescription($"\n Por que essa grade foi cancelada?: {g.atv} - {g.time}");

                                    var u = await ch.GetUserAsync(reac.UserId);

                                    await UserExtensions.SendMessageAsync(u, "", false, embed.Build());
                                }
                                else
                                {
                                    g.Principais.RemoveAll(A => A.DiscordID == acc.DiscordID);
                                    RestUserMessage x = await reac.Channel.SendMessageAsync("\n Pressione AQUI para poder Reagir \n", false, Global.EmbedGrade(g).Build());

                                    Global.MsgGrade.Remove(g.Organizador.lastmsg);
                                    Global.MsgGrade.Add(x.Id, g);
                                    g.Organizador.lastmsg = x.Id;
                                    g.Msg = x.Id;
                                }
                            }
                            if (g.Reserva.Find(a => a.DiscordID == acc.DiscordID) != null)
                            {
                                g.Reserva.RemoveAll(A => A.DiscordID == acc.DiscordID);
                                RestUserMessage x = await reac.Channel.SendMessageAsync("\n Pressione AQUI para poder Reagir \n", false, Global.EmbedGrade(g).Build());

                                Global.MsgGrade.Remove(g.Organizador.lastmsg);
                                Global.MsgGrade.Add(x.Id, g);
                                g.Organizador.lastmsg = x.Id;
                                g.Msg = x.Id;
                            }
                        }
                        else if (reac.Emote.Name.Equals("👋"))
                        {
                            if (g.Reserva.Find(a => a.DiscordID == acc.DiscordID) == null && g.Principais.Find(a => a.DiscordID == acc.DiscordID) == null)
                            {
                                g.Reserva.Add(acc);
                                RestUserMessage x = await reac.Channel.SendMessageAsync("\n Pressione AQUI para poder Reagir \n", false, Global.EmbedGrade(g).Build());

                                Global.MsgGrade.Remove(g.Organizador.lastmsg);
                                Global.MsgGrade.Add(x.Id, g);
                                g.Organizador.lastmsg = x.Id;
                                g.Msg = x.Id;
                            }
                        }
                        else if (g.Principais.Count <= g.MaxMembers)
                        {
                            if (g.Principais.Find(a => a.DiscordID == acc.DiscordID) == null && g.Reserva.Find(a => a.DiscordID == acc.DiscordID) == null)
                            {
                                g.Principais.Add(acc);
                                RestUserMessage x = await reac.Channel.SendMessageAsync("\n Pressione AQUI para poder Reagir \n", false, Global.EmbedGrade(g).Build());

                                Global.MsgGrade.Remove(g.Organizador.lastmsg);
                                Global.MsgGrade.Add(x.Id, g);
                                g.Organizador.lastmsg = x.Id;
                                g.Msg = x.Id;
                            }
                        }
                    }
                }
            }
        }