コード例 #1
0
        /// <summary>
        /// Implementación de Contrato para iniciar sesion al sistema
        /// </summary>
        /// <param name="player"></param>
        /// <exception>
        /// Este metodo puede retornar una excepcion tipo AddressAlreadyInUseEsception
        /// </exception>
        public void Login(Jugador player)
        {
            LoginResult      result;
            AdminDataManager adminDataManager = new AdminDataManager();

            if (adminDataManager.CheckNickname(player.Apodo))
            {
                if (adminDataManager.EsPasswordCorrecto(player.Contrasenia, player.Apodo))
                {
                    try
                    {
                        result = LoginResult.EsAdmin;

                        playersLoggedIn.Add(player.Apodo, PlayerCallback);
                    }
                    catch (AddressAlreadyInUseException)
                    {
                        result = LoginResult.LOGGED_PLAYER;
                    }

                    PlayerCallback.GetAdminLoginResult(result, player);
                }
                else
                {
                    result = LoginResult.PasswordIncorrecto;

                    PlayerCallback.GetAdminLoginResult(result, player);
                }
            }
            else
            {
                LoginPlayer(player);
            }
        }
コード例 #2
0
ファイル: admin.aspx.cs プロジェクト: jaydenkjh/Go_Singapore2
        public void Button2_Click(object sender, EventArgs e)
        {
            AdminDataManager ADMgr = new AdminDataManager();
            string           name  = "?";
            int  total_days        = 0;
            bool doit = true;

            try
            {
                name       = this.TextBox4.Text.ToString();
                total_days = Int32.Parse(this.TextBox5.Text);
                if (name == "" || total_days < 1)
                {
                    doit = false;
                }
            }
            catch (Exception)
            {
                doit = false;
            }
            if (doit)
            {
                ADMgr.createItinerary(name, total_days);
                DataTable dt = ADMgr.getItinerary();
                GridView2.DataSource = dt;
                GridView2.DataBind();
            }
            else
            {
                this.TextBox15.Text = "Error Encountered. Please try again.";
            }
        }
コード例 #3
0
ファイル: BanEmbed.cs プロジェクト: DavidXLiu/Kamtro-Bot
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                // Time for security checks

                /// These checks were done when the command was called - Arcy

                BanDataNode ban = new BanDataNode(Context.User, Reason);

                if (notifyTarget)
                {
                    bool sent = await BotUtils.DMUserAsync(BotUtils.GetGUser(Target.Id), new BanNotifyEmbed(ban.Reason).GetEmbed());

                    if (!sent)
                    {
                        await Context.Channel.SendMessageAsync(BotUtils.BadDMResponse);
                    }
                }

                AdminDataManager.AddBan(Target, ban);
                await Context.Channel.SendMessageAsync(BotUtils.KamtroAngry($"User {BotUtils.GetFullUsername(Target)} has been banned."));

                await ServerData.Server.AddBanAsync(Target.Id, 0, Reason);

                break;

            case diamond:
                notifyTarget = !notifyTarget;
                await UpdateEmbed();

                break;
            }
        }
コード例 #4
0
        private static void SetupFiles()
        {
            // Check for the appropriate directories.
            foreach (string dir in DataFileNames.Folders) // Check through all the necessary directories
            {
                if (!Directory.Exists(dir))               // If the directory does not exist
                {
                    Directory.CreateDirectory(dir);       // Then create it
                }
            }

            // Special case for Excel files.
            // Only used for admin stuff atm
            AdminDataManager.InitExcel();

            // Now for the files
            // This loop uses Reflection to iterate through all of the file paths and create any missing files
            // The settings.json file is the only one that needs a default template generated for it, and was handled above.
            // The passedFolders variable is so that it skips the folder array.
            bool   passedFolders = false;
            string file;

            foreach (FieldInfo fieldInfo in typeof(DataFileNames).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                if (!passedFolders)
                {
                    passedFolders = true;
                    continue;
                }

                file = fieldInfo.GetValue(null) as string;

                if (!File.Exists(file))
                {
                    Console.WriteLine($"Generated {file}");
                    File.CreateText(file).Close();  // This creates the file, then closes the unecessary stream writer
                }
            }

            AchievementManager.LoadNodeMap();

            // RESET DATES
            LastDateNode dates = JsonConvert.DeserializeObject <LastDateNode>(FileManager.ReadFullFile(DataFileNames.LastDateFile));

            if (dates == null)
            {
                dates = new LastDateNode(DateTime.UtcNow.LastSunday(), DateTime.UtcNow);
                dates.Save();
            }

            BotUtils.LastDate = dates;
        }
コード例 #5
0
        private async Task StrikeUser(SocketUser user)
        {
            // First, the classic null check
            if (BotUtils.GetGUser(Context) == null)
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("That user does not exist!"));

                KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to strike non-existant member {BotUtils.GetFullUsername(user)}");
                return;
            }

            // Flavor text for trying to strike yourself
            if (user.Id == Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("We would like to save the strikes for those that deserve it."));

                return;
            }

            // next, check to see if Kamtro has perms to ban the user
            if (!BotUtils.HighestUser(BotUtils.GetGUser(Context.Client.CurrentUser.Id), BotUtils.GetGUser(user.Id)))
            {
                await Context.Channel.SendMessageAsync(BotUtils.KamtroText("The user is higher than me, so I cannot strike them."));

                KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to strike member {BotUtils.GetFullUsername(user)} of higher status than bot");
                return;
            }

            // next, check if the caller can ban the user
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.ADMIN))
            {
                if (BotUtils.HighestUser(BotUtils.GetGUser(user.Id), BotUtils.GetGUser(Context), true))
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText("This user is higher or equal than you, and as such, you cannot strike them."));

                    KLog.Info($"User {BotUtils.GetFullUsername(Context.User)} attempted to strike member {BotUtils.GetFullUsername(user)} of higher status than caller");
                    return;
                }
            }

            if (AdminDataManager.GetStrikes(user) >= 2)
            {
                await BanUser(user);

                return;
            }

            StrikeEmbed se = new StrikeEmbed(Context, user);
            await se.Display();
        }
コード例 #6
0
ファイル: BanEmbed.cs プロジェクト: DavidXLiu/Kamtro-Bot
        public override Embed GetEmbed()
        {
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle($"Ban {BotUtils.GetFullUsername(Target)}");
            eb.WithThumbnailUrl(Target.GetAvatarUrl());
            eb.WithColor(BotUtils.Red);

            eb.AddField("User Strike Count:", AdminDataManager.GetStrikes(Target).ToString());

            eb.AddField("Will notify user?", notifyTarget ? "Yes" : "No");

            AddEmbedFields(eb);
            AddMenu(eb);

            return(eb.Build());
        }
コード例 #7
0
        public override Embed GetEmbed()
        {
            EmbedBuilder eb = new EmbedBuilder();

            eb.WithTitle($"Add Strike for {BotUtils.GetFullUsername(Target)}");
            eb.WithThumbnailUrl(Target.GetAvatarUrl());
            eb.WithColor(BotUtils.Orange);

            eb.AddField("User's current strike count:", $"{AdminDataManager.GetStrikes(Target)}");

            eb.AddField("Will notify user?", notifyUser ? "Yes":"No");

            AddEmbedFields(eb);
            AddMenu(eb);

            return(eb.Build());
        }
コード例 #8
0
        public override async Task ButtonAction(SocketReaction action)
        {
            switch (action.Emote.ToString())
            {
            case ReactionHandler.CHECK_STR:
                // On confirm
                if (!AllFieldsFilled())
                {
                    return;                          // Do nothing if the fields are not filled.
                }
                // otherwise, add the strike.
                StrikeDataNode str     = new StrikeDataNode(Context.User, Reason);
                int            strikes = AdminDataManager.AddStrike(Target, str);

                if (strikes >= 3)
                {
                    await Context.Channel.SendMessageAsync(BotUtils.KamtroText($"{BotUtils.GetFullUsername(Target)} has 3 strikes"));

                    break;
                }

                await Context.Channel.SendMessageAsync(BotUtils.KamtroText($"Added strike for {BotUtils.GetFullUsername(Target)}. They now have {strikes} strike{((strikes == 1) ? "":"s")}."));

                if (notifyUser)
                {
                    bool sent = await BotUtils.DMUserAsync(BotUtils.GetGUser(Target.Id), new StrikeNotifyEmbed(str.Reason, strikes).GetEmbed());

                    if (!sent)
                    {
                        await Context.Channel.SendMessageAsync(BotUtils.BadDMResponse);
                    }
                }

                break;

            case diamond:
                // toggles the notification of the user
                notifyUser = !notifyUser;
                await UpdateEmbed();

                return;
            }

            EventQueueManager.RemoveMessageEvent(this); // now remove the event
        }
コード例 #9
0
ファイル: admin.aspx.cs プロジェクト: jaydenkjh/Go_Singapore2
        public void Button3_Click(object sender, EventArgs e)
        {
            AdminDataManager ADMgr = new AdminDataManager();
            int    itineraryID     = -1;
            int    attractionID    = -1;
            int    day             = -1;
            string startTime       = "None";
            string endTime         = "None";
            bool   doit            = true;

            try
            {
                itineraryID  = Int32.Parse(this.TextBox6.Text);
                attractionID = Int32.Parse(this.TextBox7.Text);
                day          = Int32.Parse(this.TextBox8.Text);
                DateTime d1 = Convert.ToDateTime(this.TextBox9.Text);
                startTime = d1.ToString("HH:mm");
                DateTime d2 = Convert.ToDateTime(this.TextBox10.Text);
                endTime = d2.ToString("HH:mm");
                if (d1 > d2)
                {
                    throw new System.ArgumentException("Times invalid.", "original");
                }
                if (itineraryID <= 0 || attractionID <= 0 || day <= 0)
                {
                    doit = false;
                }
            }
            catch (Exception)
            {
                doit = false;
            }
            if (doit)
            {
                ADMgr.createItineraryDoList(itineraryID, attractionID, day, startTime, endTime);
                DataTable dt = ADMgr.getItineraryDoList();
                GridView3.DataSource = dt;
                GridView3.DataBind();
            }
            else
            {
                this.TextBox15.Text = "Error Encountered. Please try again.";
            }
        }
コード例 #10
0
        public async Task StrikeLogAsync([Remainder] string args = "")
        {
            if (!ServerData.HasPermissionLevel(BotUtils.GetGUser(Context), ServerData.PermissionLevel.MODERATOR))
            {
                return;
            }

            if (File.Exists(AdminDataManager.StrikeLogPath))
            {
                await Context.Channel.SendFileAsync(AdminDataManager.StrikeLogPath);
            }
            else
            {
                AdminDataManager.InitExcel();
                await ReplyAsync(BotUtils.KamtroText("Stirke file was missing, so I made a new one."));

                await Context.Channel.SendFileAsync(AdminDataManager.StrikeLogPath);
            }
        }
コード例 #11
0
        /// <summary>
        /// Happens whenever a user joins a server the bot is in
        /// </summary>
        /// <param name="user">The user that joined</param>
        /// <returns></returns>
        public async Task OnMemberJoin(SocketGuildUser user) {
            // Add default roles
            await user.AddRoleAsync(ServerData.Kamexican);
            await user.AddRoleAsync(ServerData.Retropolitan);


            // For cross ban.
            if(CrossBan != null && CrossBan.ContainsKey(user.Id)) {
                await BotUtils.AdminLog($"Cross-banned user {BotUtils.GetFullUsername(user)}. " + CrossBan[user.Id].GetInfoText());
                AdminDataManager.AddBan(user, new BanDataNode(Program.Client.CurrentUser, $"[X-ban | {CrossBan[user.Id].GetServer()}] {CrossBan[user.Id].Reason}"));
                await ServerData.Server.AddBanAsync(user);

                KLog.Info($"Cross-banned user {BotUtils.GetFullUsername(user)}");
                return;
            }
            // welcome user 
            Embed e = new EmbedBuilder().WithTitle("Welcome to Kamtro!").WithColor(BotUtils.Kamtro).WithDescription(Program.Settings.WelcomeMessageTemplate).Build();
            await BotUtils.DMUserAsync(user, e);
        }
コード例 #12
0
ファイル: admin.aspx.cs プロジェクト: jaydenkjh/Go_Singapore2
        public void Button5_Click(object sender, EventArgs e)
        {
            AdminDataManager ADMgr = new AdminDataManager();
            int  itineraryID       = -1;
            bool doit         = true;
            int  returnresult = -1;

            try
            {
                itineraryID = Int32.Parse(this.TextBox12.Text);
                if (itineraryID < 1)
                {
                    doit = false;
                }
            }
            catch (Exception)
            {
                doit = false;
            }
            if (doit)
            {
                returnresult = ADMgr.deleteItinerary(itineraryID);
                DataTable dt = ADMgr.getItinerary();
                GridView2.DataSource = dt;
                GridView2.DataBind();
                if (returnresult < 1)
                {
                    this.TextBox15.Text = "Failure to delete. Please try again.";
                }
                else
                {
                    this.TextBox15.Text = "Deleted successfully.";
                }
            }
            else
            {
                this.TextBox15.Text = "Error Encountered. Please try again.";
            }
        }
コード例 #13
0
ファイル: admin.aspx.cs プロジェクト: jaydenkjh/Go_Singapore2
        public void Button1_Click(object sender, EventArgs e)
        {
            AdminDataManager ADMgr       = new AdminDataManager();
            bool             doit        = true;
            string           name        = "?";
            string           image       = "?";
            string           description = "?";

            try
            {
                name        = this.TextBox1.Text.ToString();
                image       = this.FileUpload1.FileName.ToString();
                description = this.TextBox3.Text.ToString();
                if (name == "" || image == "" || description == "")
                {
                    doit = false;
                }
            }
            catch (Exception lol)
            {
                doit = false;
            }
            if (doit)
            {
                string path = "~/Views/images/attractions";
                FileUpload1.SaveAs(Server.MapPath(path) + "/" + image);
                ADMgr.createAttraction(name, image, description);
                DataTable dt = ADMgr.getAttractions();
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            else
            {
                this.TextBox15.Text = "Error Encountered. Please try again.";
            }
        }
コード例 #14
0
ファイル: admin.aspx.cs プロジェクト: jaydenkjh/Go_Singapore2
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("index.aspx");
            }

            AdminDataManager ADMgr = new AdminDataManager();

            DataTable dt = ADMgr.getAttractions();

            GridView1.DataSource = dt;
            GridView1.DataBind();

            DataTable dt2 = ADMgr.getItinerary();

            GridView2.DataSource = dt2;
            GridView2.DataBind();

            DataTable dt3 = ADMgr.getItineraryDoList();

            GridView3.DataSource = dt3;
            GridView3.DataBind();
        }
コード例 #15
0
        private void HandleConfirm()
        {
            LastPage = PageNum;

            switch (PageNum)
            {
            case 1:
                switch (OpCursor + 1)
                {
                case 1:
                    PageNum = 2;
                    break;

                case 2:
                    PageNum = 4;
                    break;

                case 3:
                    PageNum = 9;
                    break;
                }
                break;

            case 2:
                // autofill
                if (Autofill != null)
                {
                    InputFields[3][1].SetValue(Parse(Autofill.Id.ToString()));
                    InputFields[3][2].SetValue(Parse(BotUtils.GetFullUsername(Autofill)));
                    InputFields[3][3].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 1)));
                    InputFields[3][4].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 2)));
                    InputFields[3][5].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 3)));
                }

                PageNum = 3;
                break;

            case 3:
                ulong id;
                if (!string.IsNullOrWhiteSpace(UserId) && ulong.TryParse(UserId, out id))
                {
                    bool strike1Added = false;
                    bool strike2Added = false;

                    if (!string.IsNullOrWhiteSpace(Strike1Reason) && Strike1Reason != DefaultText)
                    {
                        AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike1Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 1);
                        strike1Added = true;
                    }

                    if (!string.IsNullOrWhiteSpace(Strike2Reason) && Strike2Reason != DefaultText)
                    {
                        if (!strike1Added && AdminDataManager.GetStrikes(id) == 0)
                        {
                            // Add strike 1 if it wasn't added a few lines ago, and it isn't already there
                            AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike1Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 1);
                            strike1Added = true;
                        }

                        // Add strike 2
                        AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike2Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 2);
                        strike2Added = true;
                    }

                    if (!string.IsNullOrWhiteSpace(BanReason) && BanReason != DefaultText)
                    {
                        if (!strike1Added && AdminDataManager.GetStrikes(id) == 0)
                        {
                            // Add strike 1 if it wasn't added a few lines ago, and it isn't already there
                            AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike1Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 1);
                        }

                        if (!strike2Added && AdminDataManager.GetStrikes(id) == 1)
                        {
                            AdminDataManager.AddStrike(id, new StrikeDataNode(Context.User, Strike2Reason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)), AdminDataManager.GetStrikes(id) >= 2);
                        }

                        AdminDataManager.AddBan(id, new BanDataNode(Context.User, BanReason), BotUtils.GetFullUsername(BotUtils.GetGUser(id)));
                    }

                    PageNum = 14;
                }
                break;

            case 4:
                // autofill
                if (Autofill != null)
                {
                    UserId       = Autofill.Id.ToString();
                    FullUsername = BotUtils.GetFullUsername(Autofill);
                    InputFields[6][1].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 1)));
                    InputFields[7][1].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 2)));
                    InputFields[8][1].SetValue(Parse(AdminDataManager.GetStrikeReason(Autofill.Id, 3)));
                }
                else
                {
                    return;     // you must specify a user
                }

                PageNum = 5;
                break;

            case 5:
                switch (OpCursor + 1)
                {
                case 1:
                    PageNum = 6;
                    break;

                case 2:
                    PageNum = 7;
                    break;

                case 3:
                    PageNum = 8;
                    break;
                }
                break;

            case 6:
                // handle confirm
                AdminDataManager.SetStrikeReason(Autofill.Id, 1, Strike1Reason6, BotUtils.GetGUser(Context));
                PageNum = 14;
                break;

            case 7:
                // handle confirm
                AdminDataManager.SetStrikeReason(Autofill.Id, 2, Strike2Reason7, BotUtils.GetGUser(Context));
                PageNum = 14;
                break;

            case 8:
                // handle confirm
                AdminDataManager.SetStrikeReason(Autofill.Id, 3, BanReason8, BotUtils.GetGUser(Context));
                PageNum = 14;
                break;

            case 9:
                // HC
                if (Autofill != null)
                {
                    UserId          = Autofill.Id.ToString();
                    FullUsername    = BotUtils.GetFullUsername(Autofill);
                    Strike1Reason11 = AdminDataManager.GetStrikeReason(Autofill.Id, 1);
                    Strike2Reason12 = AdminDataManager.GetStrikeReason(Autofill.Id, 2);
                    BanReason13     = AdminDataManager.GetStrikeReason(Autofill.Id, 3);
                }
                else
                {
                    return;     // you must specify a user
                }

                PageNum = 10;
                break;

            case 10:
                switch (OpCursor + 1)
                {
                case 1:
                    PageNum = 11;
                    break;

                case 2:
                    PageNum = 12;
                    break;

                case 3:
                    PageNum = 13;
                    break;
                }
                break;

            case 11:
                // handle confirm
                AdminDataManager.DeleteStrike(Autofill.Id, 1);
                PageNum = 14;
                break;

            case 12:
                // handle confirm
                AdminDataManager.DeleteStrike(Autofill.Id, 2);
                PageNum = 14;
                break;

            case 13:
                // handle confirm
                AdminDataManager.DeleteStrike(Autofill.Id, 3);
                PageNum = 14;
                break;
            }
        }