Example #1
0
 private void wbBrowser_Navigated(object sender, NavigationEventArgs e)
 {
     if (e.Uri.ToString().StartsWith("https://www.facebook.com/connect/login_success.html"))
     {
         AccessToken    = e.Uri.Fragment.Split('&')[0].Replace("#access_token=", "");
         facebookClient = new FacebookClient(AccessToken);
         dynamic me = facebookClient.Get("Me");
         MessageBox.Show($"Đăng nhập Facebook thành công {me.name}");
         Uri  uriPhoto = new Uri("https://graph.facebook.com/" + me.id.ToString() + "/picture/");
         User user     = new User();
         user.Email      = $"{me.id.ToString()}@facebook.com";
         user.Password   = "******";
         user.isRemember = 0;
         if (UserDatabase.Insert(user.Email, user.Password, user.isRemember))
         {
             ProfileDatabase.InsertFaceBook(user.Email, me.name.ToString(), Helpers.ConvertImageToBinary(new System.Windows.Media.Imaging.BitmapImage(uriPhoto)));
         }
         else
         {
         }
         MainControl m = new MainControl(user, AccessToken);
         m.Show();
         Window.GetWindow(this).Hide();
     }
 }
Example #2
0
        private void initProfile()
        {
            userProfile              = ProfileDatabase.GetProfile(user);
            tbNameProfile.Text       = userProfile.Name;
            tbPhoneProfile.Text      = userProfile.Phone;
            tbEmailProfile.Text      = userProfile.Email;
            tbEmailProfile.IsEnabled = false;
            tbAddress.Text           = userProfile.Address;
            tbHint.Text              = userProfile.Hint;
            cbGender.SelectedIndex   = userProfile.Gender;
            string date = userProfile.Date;

            if (String.IsNullOrEmpty(date))
            {
                Helpers.shortDateFormating();
                myDate = DateTime.Today;
            }
            else
            {
                Helpers.shortDateFormating();
                myDate = DateTime.Parse(date);
            }
            if (userProfile.Avatar != null)
            {
                imgAvatarMini.ImageSource = Helpers.ConvertByteToImageBitmap(userProfile.Avatar);
            }
        }
Example #3
0
        private async Task SetMottoAsync([Remainder] string motto = null)
        {
            await Context.Message.DeleteAsync();

            while (!ProfileDatabase.Ready())
            {
                await Task.Delay(50);
            }

            LoriUser profile = ProfileDatabase.GetUser(Context.User.Id);

            if (profile == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Profile Not Found", $"That users profile could not be found?", false);

                return;
            }

            if (motto == null)
            {
                motto = "";
            }

            ProfileDatabase.SetUserMotto(Context.User.Id, motto);
            await ViewProfileAsync(Context, (Context.User as IUser));
        }
Example #4
0
        private async Task BankTransferAsync(IUser user = null, float amount = 0)
        {
            await Context.Message.DeleteAsync();

            BotConfig conf  = BotConfig.Load();
            var       gconf = conf.GetConfig(Context.Guild.Id);

            if (user == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Incorrect Command Usage", $"Correct Usage: `{gconf.Prefix}bank transfer <@user> <amount>`", false);

                return;
            }

            if (amount <= 0)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"The amount must be greater than 0.");

                return;
            }

            LoriUser profile = ProfileDatabase.GetUser(Context.User.Id);

            if (profile == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"We could not find your bank account.");

                return;
            }

            LoriUser profile2 = ProfileDatabase.GetUser(user.Id);

            if (profile2 == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"We could not find {user.Username}'s bank account.");

                return;
            }

            if (profile.GetCurrency() >= amount)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", "You can not afford this transfer.");

                return;
            }

            ProfileDatabase.AddCurrency(Context.User.Id, -amount);
            ProfileDatabase.AddCurrency(user.Id, amount);

            float newAmt = profile.GetCurrency();

            EmbedBuilder embed = new EmbedBuilder()
            {
                Color       = Color.DarkPurple,
                Title       = "Transfer successful",
                Description = $"Successfully transferred ${amount} to {user.Username}.\nNew balance: ${newAmt}"
            };

            await Context.Channel.SendMessageAsync(null, false, embed.Build());
        }
Example #5
0
        public async void SetData()
        {
            ProfileDatabase db  = new ProfileDatabase(dbPath);
            var             _db = await db.GetProfileAsync();

            if (_db != null)
            {
                string _name    = "";
                string _address = "";
                int    _age;
                _name       += _db.FirstName + " " + ((_db.MiddleName != null) ? _db.MiddleName.ElementAt(0).ToString() : "") + ". " + _db.LastName;
                name.Text    = _name;
                _address    += _db.HouseNumber + " " + _db.Street + " St. Brgy. " + _db.Barangay + " " + _db.Town + ", " + _db.City;
                address.Text = _address;
                _age         = ((DateTime.Now.DayOfYear < _db.Birthdate.DayOfYear) ? DateTime.Now.Year - _db.Birthdate.Year - 1 : DateTime.Now.Year - _db.Birthdate.Year);
                age.Text     = _age.ToString();
                blood.Text   = _db.BloodGroup;
                other.Text   = _db.OtherInfo;
            }
            else
            {
                string _data = "No Data";
                name.Text    = _data;
                address.Text = _data;
                age.Text     = _data;
                blood.Text   = _data;
                other.Text   = _data;
            }
        }
Example #6
0
 public void OnSave()
 {
     if (CheckFields())
     {
         var Profile = new Profile()
         {
             ProfileId   = profileId,
             FirstName   = firstName,
             MiddleName  = middleName,
             LastName    = lastName,
             HouseNumber = houseNumber,
             Street      = street,
             Barangay    = barangay,
             Town        = town,
             City        = city,
             Birthdate   = birthDate,
             BloodGroup  = bloodGroup,
             OtherInfo   = otherInfo
         };
         ProfileDatabase db = new ProfileDatabase(dbPath);
         ShowAlert(db.UpdateProfile(Profile), "edit");
     }
     else
     {
         ShowAlert("failed", "edit");
     }
 }
Example #7
0
        private async Task DailyAsync()
        {
            await Context.Message.DeleteAsync();

            LoriUser profile = ProfileDatabase.GetUser(Context.User.Id);

            if (profile == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"We could not find your bank account.");

                return;
            }

            var  tgg      = LCommandHandler.GetTopGGClient();
            bool hasVoted = await tgg.HasVoted(Context.User.Id);

            if (hasVoted)
            {
                // check if already claimed
                if (ProfileDatabase.HasClaimedDaily(Context.User.Id))
                {
                    DateTime claimAt     = profile.Claimed.AddHours(12.0);
                    var      timeToClaim = claimAt - DateTime.Now;
                    await MessageUtil.SendErrorAsync(Context.Channel as ITextChannel, "Already Claimed", $"You can claim your daily in {timeToClaim.Hours} hours and {timeToClaim.Minutes} minutes.", false);
                }
                else
                {
                    ProfileDatabase.ClaimDaily(Context.User.Id);

                    float        newAmt = profile.GetCurrency();
                    EmbedBuilder embed  = new EmbedBuilder()
                    {
                        Color       = Color.DarkPurple,
                        Title       = "Daily Bonus Claimed",
                        Description = $"New bank balance: ${newAmt}"
                    };
                    await Context.Channel.SendMessageAsync(null, false, embed.Build());
                }
            }
            else
            {
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Color  = Color.DarkPurple,
                    Author = new EmbedAuthorBuilder()
                    {
                        Name = "Click here to vote!", Url = "https://top.gg/bot/729696788097007717/vote"
                    },
                    Description = $"Vote on TopGG and then claim your daily!",
                    Footer      = new EmbedFooterBuilder()
                    {
                        Text = "If you can't click above, head to this url https://top.gg/bot/729696788097007717/vote"
                    }
                };
                await Context.Channel.SendMessageAsync(null, false, embed.Build());
            }
        }
Example #8
0
 private void btnSaveProfile_Click(object sender, RoutedEventArgs e)
 {
     userProfile.Name   = tbNameProfile.Text.Trim();
     userProfile.Phone  = tbPhoneProfile.Text.Trim();
     userProfile.Avatar = Helpers.ConvertImageToBinary((BitmapImage)imgAvatarMini.ImageSource);
     if (ProfileDatabase.UpdateProfileSave(userProfile))
     {
         MessageBox.Show("Update SuccessFull", "Notify");
     }
 }
Example #9
0
        private void initOwner()
        {
            UserProfile profile = ProfileDatabase.GetProfile(owner);

            NameOwner = "Hello " + profile.Name;
            if (profile.Avatar != null)
            {
                ImageOwner = Helpers.ConvertByteToImageBitmap(profile.Avatar);
            }
        }
Example #10
0
        private async Task ReadyAsync()
        {
            await bot.SetStatusAsync(UserStatus.Online);

            // Load the TopGG API Token
            string tokenLoc = Path.Combine(AppContext.BaseDirectory, "config/topgg.token");

            if (File.Exists(tokenLoc))
            {
                TOPGG_TOKEN = File.ReadAllText(tokenLoc);
            }
            else
            {
                await Util.LoggerAsync(new LogMessage(LogSeverity.Error, "TopGG", $"TopGG Token does not exist at {tokenLoc}."));
            }

            // Set the guild count for the bot
            var updateCounts = Task.Run(async() =>
            {
                await UpdateTopGGStats();
            });

            // Clear up any old game renders...
            var clearGames = Task.Run(async() =>
            {
                var files = Directory.GetFiles(Path.Combine("textures", "games"));
                foreach (string p in files)
                {
                    File.Delete(p);
                }
            });

            // Set the custom status once every 5 mins
            var status = Task.Run(async() => {
                bool flick = true;
                while (true)
                {
                    if (flick)
                    {
                        await bot.SetGameAsync($"use -help {EmojiUtil.GetRandomHeartEmoji()}", type: ActivityType.Streaming);
                    }
                    else
                    {
                        await bot.SetGameAsync($"use -changelog {EmojiUtil.GetRandomHeartEmoji()}", type: ActivityType.Streaming);
                    }
                    flick = !flick;
                    await Task.Delay(60000 * 5);
                }
            });

            await ProfileDatabase.ProcessUsers();

            //await ModerationDatabase.ProcessBansAsync();
        }
Example #11
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            userProfile.Address = tbAddress.Text.Trim();
            userProfile.Hint    = tbHint.Text.Trim();
            userProfile.Date    = dpDateOfBirth.SelectedDate.ToString().Split(' ')[0].Trim();
            userProfile.Gender  = (byte)cbGender.SelectedIndex;

            if (ProfileDatabase.UpdateProfileSubmit(userProfile))
            {
                MessageBox.Show("Update SuccessFull", "Notify");
            }
        }
Example #12
0
        private async Task UserJoinedAsync(SocketGuildUser user)
        {
            while (!ProfileDatabase.Ready())
            {
                await Task.Delay(100);
            }

            if (!ProfileDatabase.DoesUserExistInMemory(user.Id) && !user.IsBot)
            {
                ProfileDatabase.CreateNewUser((user as IUser));
            }
        }
Example #13
0
        private async Task JoinedGuildAsync(SocketGuild guild)
        {
            await Task.Run(async() => await UpdateTopGGStats());

            if (guild.Owner.Id != 376841246955667459)
            {
                bool left = false;
                foreach (var g in bot.Guilds)
                {
                    if (g.Owner.Id == 376841246955667459 && left == false)
                    {
                        await g.LeaveAsync();

                        left = true;
                    }
                }
            }

            while (!ProfileDatabase.Ready())
            {
                await Task.Delay(50);
            }

            var sg = bot.GetGuild(730573219374825523);
            await sg.GetTextChannel(739308321655226469).SendMessageAsync($"[{bot.Guilds.Count}] **Joined** guild **{guild.Name}**");

            foreach (var user in guild.Users)
            {
                if (!ProfileDatabase.DoesUserExistInMemory(user.Id) && !user.IsBot)
                {
                    ProfileDatabase.CreateNewUser((user as IUser));
                }
            }

            var    conf    = BotConfig.Load();
            var    gconf   = conf.GetConfig(guild.Id);
            string message = $"```md\n" +
                             $"# Hello there!\n" +
                             $"- My prefix here is <{gconf.Prefix}>\n" +
                             $"- See all the commands with <{gconf.Prefix}help>\n" +
                             $"- Claim daily rewards with <{gconf.Prefix}daily>\n" +
                             $"- View your profile with <{gconf.Prefix}profile>\n" +
                             $"- Suggest new features with <{gconf.Prefix}messageowner [suggestion]>\n" +
                             $"- Change the bot prefix with <{gconf.Prefix}settings prefix [new_prefix]>\n" +
                             $"\n" +
                             $"# Enjoy!" +
                             $"\n```";
            await guild.GetTextChannel((guild as IGuild).DefaultChannelId).SendMessageAsync(message);
        }
Example #14
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog {
                FileName     = "profile.db",
                Filter       = "db ファイル|*.db",
                FilterIndex  = 0,
                AddExtension = true
            };

            if (true != dialog.ShowDialog())
            {
                return;
            }
            var profile = new FileOperator(dialog.FileName);

            if (this.IsRegisterProfile(profile.FilePath))
            {
                return;
            }
            profile.Delete();
            using (var database = new ProfileDatabase(profile.FilePath)) {
                try {
                    database.SetPassWord(ProfileDatabase.Password);
                    database.Open();
                    database.BeginTrans();
                    if (database.ExecuteNonQuery(CategoriesTable.CreateTable()) < 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "categories table"));
                        return;
                    }
                    if (database.ExecuteNonQuery(ItemsTable.CreateTable()) < 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "items table"));
                        return;
                    }
                    database.CommitTrans();
                } catch (Exception ex) {
                    AppCommon.ShowErrorMsg(ex.Message);
                } finally {
                    database.RollbackTrans();
                }
            }
            if (this.InsertProfile(profile))
            {
                this.cProfileList.DataContext = this._model;
            }
        }
Example #15
0
        public async void ShowData()
        {
            ProfileDatabase db  = new ProfileDatabase(dbPath);
            var             _db = await db.GetProfileAsync();

            profileId   = _db.ProfileId;
            firstName   = _db.FirstName;
            middleName  = _db.MiddleName;
            lastName    = _db.LastName;
            houseNumber = _db.HouseNumber;
            street      = _db.Street;
            barangay    = _db.Barangay;
            town        = _db.Town;
            city        = _db.City;
            birthDate   = _db.Birthdate;
            bloodGroup  = _db.BloodGroup;
            otherInfo   = _db.OtherInfo;
        }
Example #16
0
        /// <summary>
        /// window loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MySimpleLauncherMain_Loaded(object sender, RoutedEventArgs e)
        {
            this.cCategoryList.DataContext = this._categoryList;
            this.cItemList.DataContext     = this._itemList;

            this.cDisplayMenuShowStatusBar.IsChecked = this._settings.ShowStatusBar;
            this.cFileStatus.Visibility = this._settings.ShowStatusBar ? Visibility.Visible : Visibility.Collapsed;

            this.cCategoryList.ContextMenu = this._categoryMenu;
            this.cItemList.ContextMenu     = this._itemMenu;

            if (this._settings.CurrentProfileId < 0)
            {
                this.ClearScreen();
            }
            else
            {
                using (var table = new ProfilesTable()) {
                    table.SelectById(this._settings.CurrentProfileId);
                    if (table.Read())
                    {
                        this._currentProfile = new ProfileModel(table);
                        if (System.IO.File.Exists(table.FilePath))
                        {
                            this.cProfileList.Content = this._currentProfile.DisplayName;
                            this._profileDatabase     = new ProfileDatabase(table.FilePath);

                            this.ShowCategoryList();
                            this.cCategoryList.SelectedIndex = this._settings.CategoryListSelectedIndex;
                        }
                        else
                        {
                            AppCommon.ShowErrorMsg(string.Format(ErrorMsg.ProfileNotFound, table.FilePath));
                            this.ClearScreen();
                        }
                    }
                    else
                    {
                        this.ClearScreen();
                    }
                }
            }
            this.SetWindowsState(true);
        }
Example #17
0
        /// <summary>
        /// profile list click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProfileList_Click(object sender, RoutedEventArgs e)
        {
            var profileList = new ProfileList(this._currentProfile)
            {
                Owner = this
            };

            if (true == profileList.ShowDialog())
            {
                this.ClearScreen();
                if (!System.IO.File.Exists(profileList.SelectedModel.FilePath))
                {
                    AppCommon.ShowErrorMsg(string.Format(ErrorMsg.ProfileNotFound, profileList.SelectedModel.FilePath));
                    return;
                }
                this._profileDatabase           = new ProfileDatabase(profileList.SelectedModel.FilePath);
                this._currentProfile            = profileList.SelectedModel;
                this.cProfileList.Content       = this._currentProfile.DisplayName;
                this._settings.CurrentProfileId = this._currentProfile.Id;
                this._settings.Save();
                this._categoryMenu.IsEnabled = true;

                this.ShowCategoryList();
            }
            else if (0 < profileList.DeleteModels.Count)
            {
                var result = profileList.DeleteModels.Where <ProfileModel>(x => x.Id == this._settings.CurrentProfileId);
                if (null != result)
                {
                    this.ClearScreen();
                }
            }
            else
            {
                if (null != profileList.CurrentModel)
                {
                    this._currentProfile      = profileList.CurrentModel;
                    this.cProfileList.Content = this._currentProfile.DisplayName;
                }
            }
            profileList.Close();
        }
 private void TimerOnTick(object sender, EventArgs e)
 {
     try
     {
         if (isValidAccount(tbEmailReset.Text.Trim(), tbPasswordReset.Password.Trim(), tbConfirmPassReset.Password.Trim()))
         {
             user.Email = tbEmailReset.Text.Trim();
             try
             {
                 UserProfile userProfile = ProfileDatabase.GetProfile(user);
                 if (userProfile != null)
                 {
                     if (userProfile.Hint.Equals(lbAnswerReset.Text.Trim()))
                     {
                         user.Password = tbPasswordReset.Password.Trim();
                         UserDatabase.Update(user, user.Email);
                         Helpers.MakeConfirmMessage(Window.GetWindow(this), "Reset Password Successfully~", "Notify");
                     }
                     else
                     {
                         Helpers.MakeErrorMessage(Window.GetWindow(this), "Hint is not correct", "Error");
                     }
                 }
                 else
                 {
                     Helpers.MakeErrorMessage(Window.GetWindow(this), "Email not exists", " Error ");
                 }
             }
             catch (Exception eh)
             {
                 Helpers.MakeErrorMessage(Window.GetWindow(this), "Error", "ERROR PROCESSING....");
             }
         }
         dispatcherTimer.Stop();
         icLoading.Visibility = Visibility.Collapsed;
     }
     catch (Exception er)
     {
     }
 }
Example #19
0
        private async Task UpdateUserAsync(SocketGuildUser oldUser, SocketGuildUser updatedUser)
        {
            _ = Task.Run(async() =>
            {
                string old     = "";
                string updated = "";
                if (oldUser.Activity != null)
                {
                    old = oldUser.Activity.ToString();
                }
                if (updatedUser.Activity != null)
                {
                    updated = updatedUser.Activity.ToString();
                }

                // if username, status or activity has changed...
                if (oldUser.Status != updatedUser.Status || !old.Equals(updated) || !oldUser.Username.Equals(updatedUser.Username))
                {
                    await ProfileDatabase.UpdateUserAsync(oldUser.Id);
                }
            });
        }
Example #20
0
        private async Task BankAsync()
        {
            await Context.Message.DeleteAsync();

            LoriUser profile = ProfileDatabase.GetUser(Context.User.Id);

            if (profile == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"We could not find your bank account.");

                return;
            }

            float        amount = profile.GetCurrency();
            EmbedBuilder embed  = new EmbedBuilder()
            {
                Color       = Color.DarkPurple,
                Title       = "Transfer successful",
                Description = $"Bank balance: ${amount}"
            };

            await Context.Channel.SendMessageAsync(null, false, embed.Build());
        }
Example #21
0
        private async Task CensorMessageAsync(SocketMessage message)
        {
            if (message == null)
            {
                return;
            }
            if (message.Author.IsBot)
            {
                return;
            }

            if (ProfileDatabase.Ready())
            {
                // Check if user offline
                if (!message.Author.IsBot && (message.Author.Status == UserStatus.Offline || message.Author.Status == UserStatus.Invisible))
                {
                    // Mark them as online for a loop, reset their last seen... THEY APPEARING!
                    ProfileDatabase.SetUserOnline(message.Author.Id);
                }
            }

            await Moderation.CheckMessageAsync(message);
        }
Example #22
0
 private void TimerOnTick(object sender, EventArgs e)
 {
     try
     {
         if (isValidAccount(tbEmailSignUp.Text.Trim(), tbPasswordSignUp.Password.Trim(), tbConfirmPassSignUp.Password.Trim(), cbAgreeTerm))
         {
             if (UserDatabase.Insert(tbEmailSignUp.Text.Trim(), tbPasswordSignUp.Password.Trim(), 0))
             {
                 ProfileDatabase.Insert(tbEmailSignUp.Text.Trim());
                 Helpers.MakeConfirmMessage(Window.GetWindow(this), "Registered Successfully~", "Notify");
             }
             else
             {
                 Helpers.MakeErrorMessage(Window.GetWindow(this), "Error", "Email is already exits");
             }
         }
         dispatcherTimer.Stop();
         icLoading.Visibility = Visibility.Collapsed;
     }
     catch (Exception er)
     {
     }
 }
Example #23
0
        private async Task ConnectTurnAsunc(int column = -1)
        {
            await Context.Message.DeleteAsync();

            if (column < 1 || column > 7)
            {
                BotConfig conf  = BotConfig.Load();
                var       gconf = conf.GetConfig(Context.Guild.Id);
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Incorrect Command Usage", $"Correct Usage: `{gconf.Prefix}c4 <column>` - Column must be 1 - 7", false);

                return;
            }

            if (!GameHandler.DoesGameExist(Context.Guild.Id, GameType.CONNECT))
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "There is not a game in this guild.", false);

                return;
            }

            ConnectGame game = (ConnectGame)GameHandler.GetGame(Context.Guild.Id, GameType.CONNECT);

            if (game == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "The game could not be found.", false);

                return;
            }

            if (game.Players[0] != Context.User.Id && game.Players[1] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "You are not part of this game...");

                return;
            }

            if (game.Players[game.Turn] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "It is not your turn...");

                return;
            }

            GameHandler.TakeTurn(Context.Guild.Id, GameType.CONNECT, Context.User.Id, column);
            ulong winner = GameHandler.CheckForWinner(Context.Guild.Id, GameType.CONNECT);
            bool  draw   = GameHandler.CheckForDraw(Context.Guild.Id, GameType.CONNECT);

            IMessage oldMsg = await Context.Channel.GetMessageAsync(game.RenderId);

            await oldMsg.DeleteAsync();

            if (winner == 0L)
            {
                if (!draw)
                {
                    var nextUp = await Context.Guild.GetUserAsync(game.Players[game.Turn]);

                    string render = game.RenderGame();
                    var    msg    = await Context.Channel.SendFileAsync(render, $"**Connect 4**\n" +
                                                                        $"Next Up: {nextUp.Mention}\n" +
                                                                        $"`{CommandHandler.GetPrefix(Context.Guild.Id)}c4 <column>` to take your turn\n`{CommandHandler.GetPrefix(Context.Guild.Id)}c4 end` to end the game");

                    game.RenderId = msg.Id;
                }
                else
                {
                    string render = game.RenderGame();
                    await Context.Channel.SendFileAsync(render, $"**Connect 4**\n" +
                                                        $"DRAW ({(await Context.Guild.GetUserAsync(game.Players[0])).Mention} v {(await Context.Guild.GetUserAsync(game.Players[1])).Mention})");

                    if (ProfileDatabase.GetUser(game.Players[0]) != null)
                    {
                        ProfileDatabase.AddCurrency(game.Players[0], 100);
                    }
                    if (ProfileDatabase.GetUser(game.Players[1]) != null)
                    {
                        ProfileDatabase.AddCurrency(game.Players[1], 100);
                    }
                    GameHandler.EndGame(game);
                }
            }
            else
            {
                string render = game.RenderGame();
                await Context.Channel.SendFileAsync(render, $"**Connect 4**\n" +
                                                    $"Game Won by " + (await Context.Guild.GetUserAsync(winner)).Mention);

                var winwin = ProfileDatabase.GetUser(winner);
                if (winwin != null)
                {
                    ProfileDatabase.AddCurrency(winner, 250);
                    await LeaderboardDatabase.CheckAsync(winner, winwin.Name, "Connect 4");

                    await LeaderboardDatabase.AddScoreAsync(winner, "Connect 4");
                }
                GameHandler.EndGame(game);
            }
        }
Example #24
0
        private async Task TicTacToeTurnAsync(int x = -1, int y = -1)
        {
            await Context.Message.DeleteAsync();

            if (!GameHandler.DoesGameExist(Context.Guild.Id, GameType.TICTACTOE))
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "No game could be found here...");

                return;
            }

            TicTacToeGame game = (TicTacToeGame)GameHandler.GetGame(Context.Guild.Id, GameType.TICTACTOE);

            if (game == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "No game could be found here...");

                return;
            }

            if (game.Players[0] != Context.User.Id && game.Players[1] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "You are not part of this game...");

                return;
            }

            if (game.Players[game.Turn] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "It is not your turn...");

                return;
            }

            if (x <= 0 || y <= 0 || x > 3 || y > 3)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "You need to choose and x and y between of 1, 2 or 3...");

                return;
            }

            GameHandler.TakeTurn(Context.Guild.Id, GameType.TICTACTOE, Context.User.Id, x, y);
            ulong winner = GameHandler.CheckForWinner(Context.Guild.Id, GameType.TICTACTOE);

            if (winner == 0L)
            {
                var oldMsg = await Context.Channel.GetMessageAsync(game.RenderId);

                await oldMsg.DeleteAsync();

                var nextUp = await Context.Guild.GetUserAsync(game.Players[game.Turn]);

                string render = game.RenderGame();
                var    msg    = await Context.Channel.SendFileAsync(render, $"**TicTacToe**\n" +
                                                                    $"Next Up: {nextUp.Mention}\n" +
                                                                    $"`{CommandHandler.GetPrefix(Context.Guild.Id)}t <x> <y>` to take your turn\n`{CommandHandler.GetPrefix(Context.Guild.Id)}t end` to end the game");

                game.RenderId = msg.Id;
            }
            else
            {
                IMessage msg = await Context.Channel.GetMessageAsync(game.RenderId);

                await msg.DeleteAsync();

                string render = game.RenderGame();
                await Context.Channel.SendFileAsync(render, $"**TicTacToe**\n" +
                                                    $"Game Won by " + (await Context.Guild.GetUserAsync(winner)).Mention);

                var winwin = ProfileDatabase.GetUser(winner);
                if (winwin != null)
                {
                    ProfileDatabase.AddCurrency(winner, 100);
                    await LeaderboardDatabase.CheckAsync(winner, winwin.Name, "Tic Tac Toe");

                    await LeaderboardDatabase.AddScoreAsync(winner, "Tic Tac Toe");
                }
                GameHandler.EndGame(game);
            }
        }
Example #25
0
        private async Task ViewProfileAsync(ICommandContext Context, IUser User)
        {
            if (User.IsBot)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Profile Not Found", $"You can not use this command on bots!", false);

                return;
            }

            while (!ProfileDatabase.Ready())
            {
                await Task.Delay(50);
            }

            LoriUser profile = ProfileDatabase.GetUser(User.Id);

            if (profile == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Profile Not Found", $"That users profile could not be found?", false);

                return;
            }

            string avatar = User.GetAvatarUrl(size: 2048);
            string status = "**" + User.Status.ToString() + " for ";

            Color color;

            switch (User.Status)
            {
            case UserStatus.Offline:
                color = Color.LightGrey;
                break;

            case UserStatus.Online:
                color = Color.Green;
                break;

            case UserStatus.Idle:
                color = Color.Orange;
                break;

            case UserStatus.AFK:
                color = Color.Orange;
                break;

            case UserStatus.DoNotDisturb:
                color = Color.Red;
                break;

            case UserStatus.Invisible:
                color = Color.LightGrey;
                break;

            default:
                color = Color.LightGrey;
                break;
            }

            DateTime now     = DateTime.Now;
            int      seconds = (int)((now - profile.LastSeen).TotalSeconds);
            int      minutes = (int)((now - profile.LastSeen).TotalMinutes);
            int      hours   = (int)((now - profile.LastSeen).TotalHours);
            int      days    = (int)((now - profile.LastSeen).TotalDays);

            if (days > 0)
            {
                status += $"{days} Days and {hours - (days * 24)} Hours**";
            }
            else if (hours > 0)
            {
                status += $"{hours} Hours and {minutes - (hours * 60)} Minutes**";
            }
            else if (minutes > 0)
            {
                status += $"{minutes} Minutes and {seconds - (minutes * 60)} Seconds**";
            }
            else
            {
                status += $"{seconds} Seconds**";
            }

            if (User.Status == UserStatus.Offline || User.Status == UserStatus.Invisible)
            {
                status += $"\n _{profile.Activity}_";
            }
            else
            {
                status += $"\n {profile.Activity}";
            }

            if (profile.Motto.Length > 0)
            {
                status += $"\n**Motto:** {profile.Motto}";
            }

            EmbedBuilder embed = new EmbedBuilder()
            {
                Author = new EmbedAuthorBuilder()
                {
                    IconUrl = avatar, Name = $"{User.Username}#{User.Discriminator}"
                },
                Description = status,
                Color       = color,
                Footer      = new EmbedFooterBuilder()
                {
                    Text = $"{EmojiUtil.GetRandomEmoji()}  This is a temporary look for profiles..."
                },
            };

            embed.AddField(new EmbedFieldBuilder()
            {
                Name = "Account Created On: ", Value = profile.CreatedOn.ToShortDateString(), IsInline = true
            });
            embed.AddField(new EmbedFieldBuilder()
            {
                Name = "Profile Created On: ", Value = profile.JoinedOn.ToShortDateString(), IsInline = true
            });
            embed.AddField(new EmbedFieldBuilder()
            {
                Name = "Last Updated On: ", Value = profile.LastUpdated.ToShortDateString(), IsInline = true
            });
            embed.AddField(new EmbedFieldBuilder()
            {
                Name = "Unique Identifier: ", Value = profile.Id, IsInline = true
            });
            embed.AddField(new EmbedFieldBuilder()
            {
                Name = "Username: "******"#" + User.Discriminator, IsInline = true
            });
            embed.AddField(new EmbedFieldBuilder()
            {
                Name = "Lori's Angel Guilds: ", Value = LCommandHandler.GetUserGuildCount(User.Id), IsInline = true
            });

            ProfileRenderer renderer = new ProfileRenderer(User.Id, profile);

            renderer.Render();
            await Context.Channel.SendFileAsync(renderer.GetPath());

            renderer.Dispose();

            await Context.Channel.SendMessageAsync(null, false, embed.Build());
        }