示例#1
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;



            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("xkcd")
                .Description("Post either the latest comic from XKCD, or the specified comic number. rnd will provide a random comic.")
                .Parameter("comic", ParameterType.Optional)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "comic", e.Channel.IsPrivate))
                    {
                        if (e.GetArg("comic") == "")
                        {
                            XKCDComic comic = _download_serialized_json_data <XKCDComic>("http://xkcd.com/info.0.json");
                            await e.Channel.SendMessage(comic.img);
                            await e.Channel.SendMessage(comic.alt);
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                        else if (e.GetArg("comic") == "rnd")
                        {
                            XKCDComic comic = _download_serialized_json_data <XKCDComic>("http://xkcd.com/info.0.json");
                            int latestComic = comic.num;
                            int random      = new Random().Next(1, latestComic + 1);
                            string url      = String.Format("http://xkcd.com/{0}/info.0.json", random);
                            comic           = _download_serialized_json_data <XKCDComic>(url);
                            await e.Channel.SendMessage(comic.img);
                            await e.Channel.SendMessage(comic.alt);
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                        else
                        {
                            int comicnum;
                            if (Int32.TryParse(e.GetArg("comic"), out comicnum))
                            {
                                string url      = String.Format("http://xkcd.com/{0}/info.0.json", e.GetArg("comic").Trim());
                                XKCDComic comic = _download_serialized_json_data <XKCDComic>(url);
                                await e.Channel.SendMessage(comic.img);
                                await e.Channel.SendMessage(comic.alt);
                                Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                            }
                            else
                            {
                                await e.Channel.SendMessage("uh... sorry, but that doesn't look like a number " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                                Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                            }
                        }
                    }
                });
            });
        }
示例#2
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;


            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("reg")
                .Description("Register your Gamertag.")
                .Parameter("text", ParameterType.Multiple)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        switch (e.Args[0].ToLower())
                        {
                        case "xbl":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Xbox Live",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "psn":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Playstation Network",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "nnid":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Nintendo Network",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "steam":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Steam", e.Message.User.Name,
                                                                e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        case "b.n":
                            Beta.GamertagRepository.NewGamertag(e.Args[1].Trim(), "Battle.Net",
                                                                e.Message.User.Name, e.Message.User.Id);
                            await
                            e.Channel.SendMessage("Added that gamertag for you, " + e.Message.User.Name +
                                                  ".");
                            break;

                        default:
                            await
                            e.Channel.SendMessage(
                                "Sorry, I don't recognize that type of gamertag. I currently recognize the following types of Gamertags (With explination in parenthesis): ");
                            await
                            e.Channel.SendMessage(
                                "XBL (Xbox Live), PSN (Playstation Network), NNID (Nintendo Network), Steam, B.N (Battle.Net)");
                            break;
                        }
                    }
                });

                /* LEGACY REGISTER COMMANDS */

                /*
                 * cgb.CreateCommand("regpsn")
                 *  .Description("Register your PSN Gamertag.")
                 *  .Parameter("text", ParameterType.Required)
                 *  .Do(async e => {
                 *      Beta.GamertagRepository.NewGamertag(e.GetArg("text").Trim(),"Playstation Network", e.Message.User.Name,e.Message.User.Id);
                 *      await e.Channel.SendMessage("Added that gamertag for you, "+e.Message.User.Name+".");
                 *  });
                 *
                 * cgb.CreateCommand("regxbl")
                 *  .Description("Register your Xbox Live Gamertag.")
                 *  .Parameter("text", ParameterType.Required)
                 *  .Do(async e => {
                 *      Beta.GamertagRepository.NewGamertag(e.GetArg("text").Trim(),"Xbox Live", e.Message.User.Name,e.Message.User.Id);
                 *      await e.Channel.SendMessage("Added that gamertag for you, "+e.Message.User.Name+".");
                 *  });
                 *
                 * cgb.CreateCommand("regb.n")
                 *  .Description("Register your Battle.Net Gamertag.")
                 *  .Parameter("text", ParameterType.Required)
                 *  .Do(async e => {
                 *      Beta.GamertagRepository.NewGamertag(e.GetArg("text").Trim(),"Battle.Net", e.Message.User.Name, e.Message.User.Id);
                 *      await e.Channel.SendMessage("Added that gamertag for you, "+e.Message.User.Name+".");
                 *  });
                 */
                /*                                                                                                                                  */

                cgb.CreateCommand("glist")
                .Description("Returns a list of every stored Gamertag.")
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        bool anyExist = false;
                        string list   = "";
                        if (Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.GamertagType == "Steam") != null)
                        {
                            list += "**Steam Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Steam")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** Steam: **" + tag.GTag + "**\n";
                                }
                            }
                        }
                        if (Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.GamertagType == "Battle.Net") !=
                            null)
                        {
                            list += "**Battle.Net Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Battle.Net")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** Battle.Net: **" + tag.GTag +
                                               "**\n";
                                }
                            }
                        }
                        if (Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.GamertagType == "Xbox Live") !=
                            null)
                        {
                            list += "**Xbox Live Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Xbox Live")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** XBL: **" + tag.GTag + "**\n";
                                }
                            }
                        }
                        if (
                            Beta.GamertagRepository.Gamertags.FirstOrDefault(
                                g => g.GamertagType == "Playstation Network") != null)
                        {
                            list += "**Playstation Network Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Playstation Network")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** PSN: **" + tag.GTag + "**";
                                }
                            }
                        }
                        if (
                            Beta.GamertagRepository.Gamertags.FirstOrDefault(
                                g => g.GamertagType == "Nintendo Network") != null)
                        {
                            list += "**Nintendo Network Gamertags:**\n";
                            foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                            {
                                if (tag.GamertagType == "Nintendo Network")
                                {
                                    anyExist = true;
                                    list    += "Discord: **" + tag.DiscordUsername + "** NNID: **" + tag.GTag + "**\n";
                                }
                            }
                        }
                        if (anyExist)
                        {
                            await e.Channel.SendMessage(list);
                        }
                        else
                        {
                            await e.Channel.SendMessage("Sorry, I don't have any Gamertags stored yet :-/");
                        }
                    }
                });

                cgb.CreateCommand("retrieve")
                .Description("Returns all of the Gamertags stored for specified Discord user.")
                .Parameter("text", ParameterType.Required)
                .Do(async e => {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        bool found       = false;
                        string retrieved = "";
                        foreach (Gamertag tag in Beta.GamertagRepository.Gamertags)
                        {
                            if (tag.DiscordUsername == e.GetArg("text"))
                            {
                                found      = true;
                                retrieved += "Discord Username: **" + tag.DiscordUsername +
                                             "** Gamertag: **" + tag.GTag + "** Network: **" +
                                             tag.GamertagType + "** Gamertag ID: **" + tag.ID + "**\n";
                            }
                        }
                        if (found)
                        {
                            await e.Channel.SendMessage(retrieved);
                        }
                        else
                        {
                            await
                            e.Channel.SendMessage(
                                "Sorry, I didn't see any gamertags for that person.");
                        }
                    }
                });

                cgb.CreateCommand("remove")
                .Description("Removes the specified gamertag. Please provide the GamertagID, which can be retrieved using the '$retrieve' command.")
                .Parameter("ID", ParameterType.Required)
                .Do(async e => {
                    if (Beta.CheckModuleState(e, "gamertag", e.Channel.IsPrivate))
                    {
                        int id;
                        if (Int32.TryParse(e.GetArg("ID"), out id))
                        {
                            Gamertag removeTag =
                                Beta.GamertagRepository.Gamertags.FirstOrDefault(g => g.ID == id);
                            if (removeTag != null)
                            {
                                if (removeTag.DiscordID == e.Message.User.Id)
                                {
                                    Beta.GamertagRepository.Gamertags.Remove(removeTag);
                                    await
                                    e.Channel.SendMessage(
                                        "Ok cool I've removed that gamertag for you! ");
                                    Beta.GamertagRepository.Save();
                                }
                                else
                                {
                                    await
                                    e.Channel.SendMessage(
                                        "Hey that's not yours! Leave it alone, dude.");
                                }
                            }
                            else
                            {
                                await
                                e.Channel.SendMessage(
                                    "Sorry, I didn't find that gamertag. Are you sure you have the right number?");
                            }
                        }
                    }
                });
            });
        }
示例#3
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;


            manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("stats")
                .Description("Check your stats for Chat Battle, sent via PM")
                .Do(async e =>
                {
                    Beta.UserStateRepository.AddUser(e.User);
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usr.RPGHitpoints == -1)
                    {
                        usr.RPGHitpoints = usr.RPGMaxHP;
                    }
                    await e.User.SendMessage(String.Format(RPGStats, usr.RPGLevel, usr.RPGHitpoints, usr.RPGMaxHP, usr.RPGStamina, usr.RPGMaxStamina, usr.RPGGold, usr.RPGXP, usr.RPGWins, usr.RPGLosses));
                    Console.WriteLine(String.Format("[Chat Battle] {0} has requested their stats.", usr.UserName));
                    Console.WriteLine(String.Format("[Chat Battle] " + RPGStats, usr.RPGLevel, usr.RPGHitpoints, usr.RPGMaxHP, usr.RPGStamina, usr.RPGMaxStamina, usr.RPGGold, usr.RPGXP, usr.RPGWins, usr.RPGLosses));
                });

                cgb.CreateCommand("res")
                .Description("Spend a percentage of your gold to return you to the living with max health! Beta will probably take some of your gold.")
                .Do(async e =>
                {
                    UserState target = Beta.UserStateRepository.GetUserState(e.User.Id);
                    int cost         = Convert.ToInt32(target.RPGGold * (.1 + (.01 * target.RPGLevel)));

                    if (!target.Alive)
                    {
                        Beta.UserStateRepository.ResUser(cost, target.UserId);
                        await e.User.SendMessage("Heroes never die!");
                        await e.User.SendMessage(String.Format("Oh. Also I took {0} gold. You know, for my trouble ;D", cost));
                    }
                    else
                    {
                        await e.User.SendMessage("Sorry, bub. Looks like you're still kicking, try dying first.");
                    }
                });


                cgb.CreateCommand("push")
                .Description("Pushes the target out of an airlock. Can only be used by Admins")
                .Parameter("target", ParameterType.Unparsed)
                .Do(async e =>
                {
                    bool nuke        = false;
                    string msg       = "";
                    string target    = e.GetArg("target").Trim();
                    UserState pusher = Beta.UserStateRepository.GetUserState(e.User.Id);
                    UserState pushee = Beta.UserStateRepository.UserStates.FirstOrDefault(us => us.UserName == target);
                    bool isAdmin     = Admins.Contains(target.ToLower());
                    Console.WriteLine("isAdmin: " + isAdmin + " Target: " + target);
                    switch (e.User.Name)
                    {
                    case "Dart":
                        nuke = true;
                        msg  = String.Format(DartAirlock, target);
                        break;

                    case "Kalis":
                        nuke = true;
                        msg  = String.Format(KalisAirlock, target);
                        break;

                    case "Sizer":
                        nuke = true;
                        msg  = String.Format(SizerAirlock, target);
                        break;

                    case "FriendlyFire":
                        nuke = true;
                        msg  = String.Format(FFAirlock, target);
                        break;

                    case "DarkForce":
                        nuke = true;
                        msg  = String.Format(DFAirlock, target);
                        break;

                    default:
                        if (e.Channel.Id == 93924120042934272)
                        {
                            msg = String.Format(AirlockFail, e.User.Name, target);
                            if (isAdmin)
                            {
                                msg = String.Format(AdminFail, e.User.Name, target);
                            }
                        }
                        break;
                    }
                    if (msg != "")
                    {
                        await e.Channel.SendMessage(msg);
                    }
                    if (nuke && pushee != null)
                    {
                        await e.Channel.SendMessage(
                            String.Format("As {0}'s body floats through space they slowly begin to lose consciousness...", target));
                        await e.Channel.SendMessage(String.Format("{0} has slain {1}! FATALITY!", e.User.Name, target));
                        pusher.Die();
                    }
                    else if (!nuke && pusher != null)
                    {
                        await e.Channel.SendMessage(
                            String.Format(
                                "As {0}'s body floats through space they slowly begin to lose consciousness...", pusher.UserName));
                        await e.Channel.SendMessage(
                            String.Format("{0} managed to get themselves lost in the cold vacuum of space...", pusher.UserName));
                        Thread.Sleep(1500);
                        await
                        e.Channel.SendMessage(
                            String.Format("A robotic hand closes on {0}'s wrist and drags them back in. They feel exhausted, but they'll live.", e.User.Name));
                        pusher.RPGStamina = 0;
                    }
                });

                cgb.CreateCommand("attack")
                .Description("Attack your target")
                .Parameter("target", ParameterType.Unparsed)
                .Do(async e =>
                {
                    Result combatResult;

                    Result npcResult   = null;
                    BetaState          = (BetaUserState)Beta.UserStateRepository.NPCUserStates.FirstOrDefault(nu => nu.UserName == "Beta");
                    UserState attacker = Beta.UserStateRepository.GetUserState(e.User.Id);
                    UserState target   = null;
                    UserState beta     = Beta.UserStateRepository.UserStates.FirstOrDefault(us => us.UserName == "Beta");
                    if (attacker == null)
                    {
                        Beta.UserStateRepository.AddUser(e.User);
                        attacker = Beta.UserStateRepository.GetUserState(e.User.Id);
                    }
                    decimal stamCost = (decimal)(attacker.RPGLevel * .25);
                    int damage       = (int)(stamCost * r.Next(4, 50));
                    if (Beta.CheckModuleState(e, "battle", e.Channel.IsPrivate) && attacker.Alive)
                    {
                        if (ValidChatBattleTarget(e))
                        {
                            target = GetTargetUserState(e);
                        }
                        if (target != null && attacker.RPGStamina >= stamCost)
                        {
                            attacker.RPGStamina -= stamCost;
                            if (attacker.RPGStamina < stamCost)
                            {
                                await e.User.SendMessage("You feel exhausted...");
                            }
                            if (target.RPGHitpoints == 0 && target.UserName == "Beta")
                            {
                                target.Res(1);
                            }
                            if (!target.Alive)
                            {
                                await
                                e.Channel.SendMessage(
                                    "Oh. Sorry, it looks like that target is currently dead. They'll have to res themselves before you can attack them for gold and xp!");
                            }
                            else
                            {
                                combatResult = attacker.Attack(target, e);
                                await
                                e.Channel.SendMessage(
                                    String.Format(
                                        "{0} attacked {1} with the {2} {3} of {4} for {5} points of damage! You drew blood!",
                                        e.User.Name, e.GetArg("target"), WeaponPrefixList.GetRandom(),
                                        WeaponList.GetRandom(),
                                        WeaponSuffixList.GetRandom(), combatResult.Damage));


                                if (!target.IsBot())
                                {
                                    #region Target Death Result

                                    if (target.UserId != attacker.UserId)
                                    {
                                        if (combatResult.TargetDead)
                                        {
                                            await
                                            e.Channel.SendMessage(
                                                String.Format(
                                                    "That hit killed {0}! {1} found {2} gold on their corpse! Gained {3} XP!",
                                                    target.UserName, e.User.Name, combatResult.Spoils.Gold,
                                                    combatResult.Spoils.XP));
                                            attacker.CheckLevelUp(e);
                                            if (combatResult.Spoils.HealthPot > 0 || combatResult.Spoils.StamPot > 0)
                                            {
                                                await
                                                e.Channel.SendMessage(
                                                    String.Format(
                                                        "Looks like you also managed to find some potions! Gained {0} Health Potions and {1} Stamina Potions.",
                                                        combatResult.Spoils.HealthPot,
                                                        combatResult.Spoils.StamPot));
                                            }
                                        }
                                    }
                                    #endregion

                                    #region Player Attacked Themselves

                                    else if (target.UserId == attacker.UserId)
                                    {
                                        await e.Channel.SendMessage(
                                            String.Format(
                                                "Oh. Looks like {0} managed to kill themselves. You lost {1} XP.",
                                                e.User.Name, target.RPGLevel * 3));
                                        target.Die();
                                        if (r.Next(1, 5) == 3)
                                        {
                                            int lostGold = r.Next(1, 5) * target.RPGLevel;
                                            await
                                            e.Channel.SendMessage(
                                                String.Format(
                                                    "Also, a bandit seems to have picked your corpse's pocket. Lose {0} gold.",
                                                    lostGold));
                                            if (lostGold > target.RPGGold)
                                            {
                                                UserState.BanditGold += target.RPGGold;
                                                target.RPGGold        = 0;
                                            }
                                            else
                                            {
                                                UserState.BanditGold += lostGold;
                                                target.RPGGold       -= lostGold;
                                            }
                                            if (3 * target.RPGLevel > target.RPGXP)
                                            {
                                                target.RPGXP = 0;
                                            }
                                            else
                                            {
                                                target.RPGXP -= target.RPGLevel * 3;
                                            }
                                        }
                                    }

                                    #endregion
                                }
                                else
                                {
                                    /*if (target.UserName == "R2-D2")
                                     * {
                                     *  //This section is going to be a little messy until the new UserStates are in place.
                                     *  BetaState.DefendBot(target,attacker, e, combatResult);
                                     * }*/
                                    if (target.UserName == "Beta")
                                    {
                                        BetaState.CounterAttack(attacker, e, combatResult);
                                    }
                                    else
                                    {
                                        npcResult = target.Attack(attacker, e);
                                        await
                                        e.Channel.SendMessage(
                                            String.Format(
                                                "{0} struck back with the {1}{2} of {3} for {4} points of damage!", target.UserName, WeaponPrefixList.GetRandom(), WeaponList.GetRandom(), WeaponSuffixList.GetRandom(), npcResult.Damage));

                                        //Both died
                                        if (npcResult.TargetDead && combatResult.TargetDead)
                                        {
                                            await
                                            e.Channel.SendMessage(
                                                String.Format(
                                                    "{0} and {1} managed to kill each other! {0} gained {2} XP and {1} gained {3} XP",
                                                    target.UserName, attacker.UserName, npcResult.Spoils.XP, combatResult.Spoils.XP));
                                            Beta.UserStateRepository.NPCUserStates.Remove((NPCUserState)target);
                                        }
                                        //NPC died, player survived
                                        else if (!npcResult.TargetDead && combatResult.TargetDead)
                                        {
                                            await e.Channel.SendMessage(String.Format("{0} managed to kill the {1}! Gained {2} XP, {3} Gold, {4} Health Potions, and {5} Stamina Potions", attacker.UserName, target.UserName, combatResult.Spoils.XP, combatResult.Spoils.Gold, combatResult.Spoils.HealthPot, combatResult.Spoils.StamPot));
                                            Beta.UserStateRepository.NPCUserStates.Remove((NPCUserState)target);
                                        }
                                        //Player died, NPC survived
                                        else if (npcResult.TargetDead && !combatResult.TargetDead)
                                        {
                                            await e.Channel.SendMessage(String.Format("{0} managed to kill the {1}! Gained {2} XP, {3} Gold, {4} Health Potions, and {5} Stamina Potions", target.UserName, attacker.UserName, combatResult.Spoils.XP, combatResult.Spoils.Gold, combatResult.Spoils.HealthPot, combatResult.Spoils.StamPot));
                                        }
                                    }
                                }
                            }
                        }
                        else if (target == null)
                        {
                            await
                            e.Channel.SendMessage(
                                String.Format(
                                    "{0} attacked {1} with the {2} {3} of {4} for {5} points of damage!",
                                    e.User.Name, e.GetArg("target"), WeaponPrefixList.GetRandom(),
                                    WeaponList.GetRandom(),
                                    WeaponSuffixList.GetRandom(), damage));
                        }
                    }
                    else if (!attacker.Alive)
                    {
                        await e.User.SendMessage("YOU'RE DEAD DING DONG!");
                    }
                });

                cgb.CreateCommand("drink")
                .Description("Drink either a Stamina or Healing potion. Stamina potions recover 2-4 Stamina and Healing potions recover 12-25 Hitpoints")
                .Parameter("potionType", ParameterType.Unparsed)
                .Do(async e =>
                {
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usr == null)
                    {
                        Beta.UserStateRepository.AddUser(e.User);
                        usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    }
                    switch (e.GetArg("potionType").Trim().ToLower())
                    {
                    case "healing":
                        if (usr.RPGHealingPotions > 1)
                        {
                            await
                            e.User.SendMessage(String.Format("You drank a healing poition! Healed for {0}!",
                                                             usr.DrinkHealingPotion()));
                        }
                        else
                        {
                            await e.User.SendMessage("You don't even have any healing potions!");
                        }
                        break;

                    case "stamina":
                        if (usr.RPGStaminaPotions > 1)
                        {
                            await
                            e.User.SendMessage(String.Format("You drank a Stamina poition! Recovered {0} stamina!",
                                                             usr.DrinkStaminaPotion()));
                        }
                        else
                        {
                            await e.User.SendMessage("You don't even have any Stamina potions!");
                        }
                        break;

                    default:
                        await
                        e.User.SendMessage(
                            "Sorry, I don't recognize that type of potion. Please use either \"$drink healing\" or \"$drink stamina\".");
                        break;
                    }
                });

                cgb.CreateCommand("npclist")
                .Description("Returns a list of NPCs which can be attacked")
                .Do(async e =>
                {
                    string msg = "The following NPCs are available for attack:\n";
                    foreach (NPCUserState npc in Beta.UserStateRepository.NPCUserStates)
                    {
                        msg += npc.UserName + " Level: " + npc.RPGLevel + "\n";
                    }
                    await e.User.SendMessage(msg);
                });

                cgb.CreateCommand("inventory")
                .Alias("inv")
                .Description("Check your inventory for Chat battle, sent via PM")
                .Do(async e =>
                {
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    await e.User.SendMessage(String.Format(RPGInv, usr.RPGHealingPotions, usr.RPGStaminaPotions));
                });
            });
        }
示例#4
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;
            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("Tweet")
                .Description("Send a tweet on behalf of Beta!")
                .Parameter("text", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "twitter", e.Channel.IsPrivate))
                    {
                        string tweet = e.GetArg("text");
                        if (System.Text.RegularExpressions.Regex.IsMatch(tweet, "<@d{16}>"))
                        {
                            string[] arg = tweet.Split(' ');
                            for (int i = 0; i < arg.Length; i++)
                            {
                                if (System.Text.RegularExpressions.Regex.IsMatch(arg[i], "<@d{16}>"))
                                {
                                    string username = arg[i];
                                    username        = username.Replace("<@", null);
                                    username        = username.Replace(">", null);
                                    Console.WriteLine(username);
                                    ulong id;
                                    ulong.TryParse(username, out id);
                                    arg[i] = e.Message.MentionedUsers.FirstOrDefault(x => x.Id == id).Name;
                                }
                            }
                            tweet = String.Join(" ", arg);
                        }
                        Auth.SetUserCredentials(Beta.Config.TwitterConsumerKey, Beta.Config.TwitterConsumerSecret, Beta.Config.TwitterAccessToken, Beta.Config.TwitterAccessSecret);
                        if (Tweetinvi.Tweet.PublishTweet(e.GetArg("text")) == null)
                        {
                            await e.Channel.SendMessage("Something went wrong... I didn't send that tweet for you.");
                        }
                        else
                        {
                            await e.Channel.SendMessage("I sent that tweet for you! Hopefully people like it!");
                        }
                    }
                });

                cgb.CreateCommand("test")
                .Description("Test for HillaryTrumpBot!")
                .Do(async e =>
                {
                    var theDonald = Tweetinvi.User.GetUserFromId(25073877);
                    await e.Channel.SendMessage("Donald Trump has " + Timeline.GetUserTimeline(theDonald.ScreenName, 33000).Count() + " Tweets!");
                    var presidentClinton = Tweetinvi.User.GetUserFromId(1339835893);
                    await e.Channel.SendMessage("Hillary Clinton has " + Timeline.GetUserTimeline(presidentClinton.ScreenName, 9000).Count() + " Tweets!");
                });

                cgb.CreateCommand("Follow")
                .Description("Follow the specified user on Twitter")
                .Parameter("user", ParameterType.Required)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "twitter", e.Channel.IsPrivate))
                    {
                        var User = new UserIdentifier(e.GetArg("user"));
                        if (User == null)
                        {
                            await e.Channel.SendMessage("Sorry, I didn't see that user out in the Twitosphere...");
                        }
                        else
                        {
                            Friendship.FriendshipController.CreateFriendshipWith(User);
                        }
                    }
                });
            });
        }
示例#5
0
文件: QuoteModule.cs 项目: powli/Beta
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;

            manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("quote")
                .Description("Pull up a random quote from the specified speaker.")
                .Parameter("speaker", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "quote", e.Channel.IsPrivate))
                    {
                        string name   = e.GetArg("speaker").Trim();
                        Author author = Beta.QuoteRepository.GetAuthor(name);
                        if (name.ToLower() == "random")
                        {
                            author = Beta.QuoteRepository.Authors.GetRandom();
                        }
                        if (author == null)
                        {
                            await e.Channel.SendMessage("Could not find author: '" + e.GetArg("Speaker") + "'");
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }

                        else
                        {
                            string reply = string.Format(_QuoteFormat,
                                                         ReplaceVariables(author.Quotes.GetRandom().Text, e.Message.User.Name), author.Name);
                            await e.Channel.SendMessage(reply);
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                    }
                });

                cgb.CreateCommand("list")
                .Description("Return a numbered list of all quotes. Will be sent as a PM.")
                .Parameter("speaker", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "quote", e.Channel.IsPrivate))
                    {
                        string name   = e.GetArg("speaker").Trim();
                        Author author = Beta.QuoteRepository.GetAuthor(name);
                        if (author == null)
                        {
                            await e.Channel.SendMessage("Could not find author: '" + e.GetArg("Speaker") + "'");
                        }
                        else
                        {
                            string reply = "";
                            int index    = 1;
                            Console.WriteLine(author.Quotes[0].Text);
                            foreach (Quote quote in author.Quotes)
                            {
                                reply += index++ + ". " + quote.Text + "\r\n";
                            }
                            await e.User.SendMessage(reply);
                        }
                    }
                });

                cgb.CreateCommand("delete")
                .Description("Delete the specified quote, by number, for the specified author. EX) '$delete Beta|1' would delete the first quote by Beta. Please use the 'List' command to retrieve quote numbers.")
                .Parameter("text", ParameterType.Unparsed)
                .MinPermissions((int)PermissionLevel.ChannelModerator)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "quote", e.Channel.IsPrivate))
                    {
                        var args = e.GetArg("text").Split('|');
                        Author existingAuthor = Beta.QuoteRepository.GetAuthor(args[0]);
                        int index;
                        if (Int32.TryParse(args[1], out index))
                        {
                            if (existingAuthor == null)
                            {
                                await e.Channel.SendMessage("Sorry, I don't recognize that author, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                                Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                            }
                            else
                            {
                                await e.Channel.SendMessage(Beta.QuoteRepository.DeleteQuote(existingAuthor, index));
                                if (existingAuthor.Quotes.Count == 0)
                                {
                                    Beta.QuoteRepository.RemoveAuthor(existingAuthor);
                                    await
                                    e.Channel.SendMessage("Looks like we're actually out of quotes for " +
                                                          existingAuthor +
                                                          " so I'll remove it from the list as well, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                                    Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                                }
                            }
                        }
                        else
                        {
                            await e.Channel.SendMessage("Sorry, but that doesn't look like a number to me, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }
                    }
                });

                cgb.CreateCommand("quotable")
                .Description("Return a list of all speakers we have stored quotes for. Will be sent as a PM.")
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "quote", e.Channel.IsPrivate))
                    {
                        string msg = "";
                        await e.User.SendMessage("Oh yeah sure one sec... I got quotes for all these guys: ");
                        Beta.QuoteRepository.Authors = Beta.QuoteRepository.Authors.OrderBy(item => item.Name).ToList();
                        foreach (Author author in Beta.QuoteRepository.Authors)
                        {
                            //Before adding the author name to the message, make sure we're not exceeding 2000 characters
                            if ((author.Name.Length + msg.Length) > 2000)
                            {//If we are, send the message, blank it out, and start building a new one.
                                await e.User.SendMessage(msg);
                                msg  = "";
                                msg += author.Name + "\n";
                            }
                            else
                            {//Otherwise, just add the author name to the list and move on.
                                msg += author.Name + "\n";
                            }
                        }
                        if (msg != "")
                        {
                            await e.User.SendMessage(msg);
                        }
                    }
                });

                cgb.CreateCommand("convert")
                .MinPermissions((int)PermissionLevel.BotOwner)
                .Do(e =>
                {
                    if (Beta.CheckModuleState(e, "quote", e.Channel.IsPrivate))
                    {
                        Beta.conv.Convert(Beta.QuoteRepository);
                    }
                });

                cgb.CreateCommand("add")
                .Description("Add a quote for the specified Author. $add Author|Whatever that author said.")
                .Parameter("text", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "quote", e.Channel.IsPrivate))
                    {
                        var args = e.GetArg("text").Split('|');
                        Author existingAuthor = Beta.QuoteRepository.GetAuthor(args[0]);
                        Beta.QuoteRepository.AddQuote(args[0], args[1], e.User.Name);

                        if (existingAuthor != null)
                        {
                            await
                            e.Channel.SendMessage(String.Format(
                                                      "Successfully added another quote from '{0}', " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "", existingAuthor.Name));
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                        else
                        {
                            await
                            e.Channel.SendMessage(String.Format("Successfully added quote from '{0}', " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".",
                                                                args[0]));
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }

                        // Save after every add
                        Beta.QuoteRepository.Save();
                    }
                });
            });
        }
示例#6
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;


            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("say")
                .MinPermissions((int)PermissionLevel.BotOwner)      // An unrestricted say command is a bad idea
                .Description("Make the bot speak!")
                .Parameter("text", ParameterType.Unparsed)
                .Do(async e =>
                {
                    await e.Channel.SendMessage(e.GetArg("text"));
                    await e.Message.Delete();
                    Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 10);
                });

                cgb.CreateCommand("setmotd")
                .MinPermissions((int)PermissionLevel.ChannelModerator)
                .Description("Set the Message of the Day for this channel!")
                .Parameter("text", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.ChannelStateRepository.VerifyChannelExists(e.Channel.Id))
                    {
                        Beta.ChannelStateRepository.ChannelStates.FirstOrDefault(cs => cs.ChannelID == e.Channel.Id).MOTD = e.GetArg("text");
                        Beta.ChannelStateRepository.Save();
                        await e.User.SendMessage("Ok " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ", I set that message for you!");
                        await e.Message.Delete();
                        await e.Channel.SendMessage(Beta.ChannelStateRepository.GetChannelState(e.Channel.Id).MOTD);
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 10);
                    }
                });

                cgb.CreateCommand("trust")
                .MinPermissions((int)PermissionLevel.BotOwner)
                .Description("Adds the specified user to the trusted user list.")
                .Parameter("uid", ParameterType.Unparsed)
                .Do(async e =>
                {
                    ulong uid;
                    if (ulong.TryParse(e.GetArg("uid"), out uid))
                    {
                        Beta.Config._TrustedUsers.Add(uid);
                        ConfigHandler.SaveConfig();
                        await e.Channel.SendMessage("You really trust that one? Well, _you're_ the boss.");
                    }
                    else
                    {
                        await e.Channel.SendMessage("Who?");
                    }
                });


                cgb.CreateCommand("initstates")
                .MinPermissions((int)PermissionLevel.BotOwner)
                .Description("Administration tool, initiate channel states for all current channels.")
                .Do(async e =>
                {
                    foreach (var server in _client.Servers)
                    {
                        foreach (var channel in server.AllChannels)
                        {
                            Beta.ChannelStateRepository.AddChannel(channel, server);
                        }
                        Beta.ServerStateRepository.AddServer(server);
                    }
                    await e.Channel.SendMessage("All set, Boss!");
                });

                cgb.CreateCommand("roll")
                .Description(
                    @"Make Beta roll the specified number of dice. For Example typing $Roll 3d12 would cause Beta to return the results of rolling 3 12-sided die. You could also role a single 12-sided die with d12.")
                .Parameter("roll", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "roll", e.Channel.IsPrivate))
                    {
                        var arg       = e.GetArg("roll");
                        var arguments = arg.Split('d').Where(s => !string.IsNullOrEmpty(s)).ToList();
                        int sides, times, modifier;

                        if (arguments.Count == 1)
                        {
                            if (arguments[0].Contains("+"))
                            {
                                arguments = arguments[0].Split('+').ToList();
                                if (int.TryParse(arguments[0], out sides))
                                {
                                    var dice = new Dice(sides);
                                    var temp = dice.Roll();
                                    if (int.TryParse(arguments[1], out modifier))
                                    {
                                        await
                                        e.Channel.SendMessage(
                                            string.Format("Rolled one d{0}) plus {1} and got a total of {2}", sides,
                                                          modifier, temp + modifier));
                                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                                    }
                                    else
                                    {
                                        await e.Channel.SendMessage("Sorry, I don't recognize that number, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "");
                                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                                    }
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Sorry, I don't recognize that number, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "");
                                    Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                                }
                            }
                            else
                            {
                                if (int.TryParse(arguments[0], out sides))
                                {
                                    var dice = new Dice(sides);
                                    await
                                    e.Channel.SendMessage(string.Format("Rolled one d{0} and got a total of {1}",
                                                                        sides, dice.Roll()));
                                    Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Sorry, I don't recognize that number, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "");
                                    Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                                }
                            }
                        }
                        else if (arguments.Count == 2)
                        {
                            if (int.TryParse(arguments[0], out times))
                            {
                                if (arguments[1].Contains("+"))
                                {
                                    arguments = arguments[1].Split('+').ToList();
                                    if (int.TryParse(arguments[0], out sides))
                                    {
                                        var dice = new Dice(sides);
                                        var temp = dice.Roll(times);
                                        if (int.TryParse(arguments[1], out modifier))
                                        {
                                            await
                                            e.Channel.SendMessage(
                                                string.Format("Rolled {0} d{1} plus {2} and got a total of {3}",
                                                              times, sides, modifier, temp.Total + modifier));
                                            await
                                            e.Channel.SendMessage(string.Format("Individual Rolls: {0}",
                                                                                string.Join(",", temp.Rolls)));
                                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                                        }
                                        else
                                        {
                                            await e.Channel.SendMessage("Sorry, I don't recognize that number, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "");
                                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                                        }
                                    }
                                    else
                                    {
                                        await e.Channel.SendMessage("Sorry, I don't recognize that number, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "");
                                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                                    }
                                }
                                else
                                {
                                    if (int.TryParse(arguments[1], out sides))
                                    {
                                        var dice = new Dice(sides);
                                        var temp = dice.Roll(times);
                                        await
                                        e.Channel.SendMessage(string.Format(
                                                                  "Rolled {0} d{1} and got a total of {2}", times, sides, temp.Total));
                                        await
                                        e.Channel.SendMessage(string.Format("Individual Rolls: {0}",
                                                                            string.Join(",", temp.Rolls)));
                                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                                    }
                                    else
                                    {
                                        await e.Channel.SendMessage("Sorry, I don't recognize that number, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "");
                                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                                    }
                                }
                            }
                        }
                    }
                });

                cgb.CreateCommand("ask")
                .Description("Ask Beta a yes or no question!")
                .Parameter("text", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "ask", e.Channel.IsPrivate))
                    {
                        await e.Channel.SendMessage(Utilities._8BallResponses.GetRandom());
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                    }
                });

                cgb.CreateCommand("motd")
                .Description("Show the MotD for the current channel")
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "motd", e.Channel.IsPrivate))
                    {
                        if (Beta.ChannelStateRepository.VerifyChannelExists(e.Channel.Id))
                        {
                            await
                            e.Channel.SendMessage(Beta.ChannelStateRepository.GetChannelState(e.Channel.Id).MOTD);
                            await e.Message.Delete();
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                        else
                        {
                            await
                            e.Channel.SendMessage(
                                "Sorry " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ", there is no message! harass the Admins or something.");
                        }
                    }
                });

                cgb.CreateCommand("forgive")
                .Description(
                    "Forgives certain violations. Currently recognizes a username (NOT display name) as a parameter.")
                .Parameter("User", ParameterType.Required)
                .MinPermissions((int)PermissionLevel.ServerAdmin)
                .Do(async e =>
                {
                    UserState user = Beta.UserStateRepository.UserStates.FirstOrDefault(us => us.UserName.ToLower() == e.GetArg("User").ToLower());
                    if (user != null)
                    {
                        await e.Channel.SendMessage("You got it " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "!");

                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                    }
                    else
                    {
                        await e.Channel.SendMessage("Sorry, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ". I don't recognize that meatbag.");
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                    }
                });

                cgb.CreateCommand("stoggle")
                .Description(
                    "Toogles whether a module is enabled for the entire server. Please use one of the following options: Ask, Comic, Gamertag, MotD, Note, Quote, Roll, Table, Twitter, Politics, Battle")
                .MinPermissions((int)PermissionLevel.ServerAdmin)
                .Parameter("Module", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (TogglableCommands.Contains(e.GetArg("Module").ToLower()))
                    {
                        bool changedState =
                            Beta.ServerStateRepository.GetServerState(e.Server.Id)
                            .ToggleFeatureBool(e.GetArg("Module").ToLower());
                        await
                        e.Channel.SendMessage(
                            String.Format("Ok " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ", I've toggled the setting enabling {0} so now it's set to {1} for the entire server",
                                          e.GetArg("Module"), changedState.ToString()));
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                    }
                    else
                    {
                        await e.Channel.SendMessage(String.Format("Sorry, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ". I don't see a module named {0} in the approved list...", e.GetArg("Module")))
                        ;
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                    }
                    Beta.ServerStateRepository.Save();
                });

                cgb.CreateCommand("toggle")
                .Description(
                    "Toogles whether a module is enabled for the channel. Please use one of the following options: Ask, Comic, Gamertag, MotD, Note, Quote, Roll, Table, Twitter, Politics, Battle")
                .MinPermissions((int)PermissionLevel.ChannelAdmin)
                .Parameter("Module", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (TogglableCommands.Contains(e.GetArg("Module").ToLower()))
                    {
                        bool changedState =
                            Beta.ChannelStateRepository.GetChannelState(e.Channel.Id)
                            .ToggleFeatureBool(e.GetArg("Module").ToLower());
                        await
                        e.Channel.SendMessage(
                            String.Format("Ok, I've toggled the setting enabling {0} so now it's set to {1}",
                                          e.GetArg("Module"), changedState.ToString()));
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                    }
                    else
                    {
                        await e.Channel.SendMessage(String.Format("Sorry, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ". I don't see a module named {0} in the approved list...", e.GetArg("Module")))
                        ;
                        Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                    }
                    Beta.ChannelStateRepository.Save();
                });

                cgb.CreateCommand("senabled")
                .Description("Displays the state of each module for the server.")
                .MinPermissions((int)PermissionLevel.ServerAdmin)
                .Do(async e =>
                {
                    if (Beta.ServerStateRepository.VerifyStateExists(e.Server.Id))
                    {
                        ServerState srvr = Beta.ServerStateRepository.GetServerState(e.Server.Id);
                        string msg       = "";
                        msg += "Ask  :  " + srvr.AskEnabled + "\n";
                        msg += "Comic  :  " + srvr.ComicModuleEnabled + "\n";
                        msg += "Gamertag  :  " + srvr.GamertagModuleEnabled + "\n";
                        msg += "MotD  :  " + srvr.MOTDEnabled + "\n";
                        msg += "Note : " + srvr.NoteModuleEnabled + "\n";
                        msg += "Quote  :  " + srvr.QuoteModuleEnabled + "\n";
                        msg += "Roll  :  " + srvr.RollEnabled + "\n";
                        msg += "Table  :  " + srvr.TableUnflipEnabled + "\n";
                        msg += "Twitter  :  " + srvr.TwitterModuleEnabled + "\n";
                        msg += "Politics : " + srvr.PoliticsEnabled + "\n";
                        msg += "Chat Battle : " + srvr.ChatBattleEnabled + "\n";
                        msg += "Chatty Mode : " + srvr.ChattyModeEnabled + "\n";
                        msg += "Markov Listener Enabled : " + srvr.MarkovListenerEnabled + "\n";
                        msg += "Meme Generator Enabled : " + srvr.MemeGenEnabled + "\n";
                        msg += "Cram Enabled: " + srvr.CramEnabled + "\n";
                        await e.Channel.SendMessage(msg);
                    }
                });

                cgb.CreateCommand("enabled")
                .Description("Displays the state of each module for the channel.")
                .MinPermissions((int)PermissionLevel.ChannelAdmin)
                .Do(async e =>
                {
                    if (Beta.ChannelStateRepository.VerifyChannelExists(e.Channel.Id))
                    {
                        ChannelState chnl = Beta.ChannelStateRepository.GetChannelState(e.Channel.Id);
                        string msg        = "";
                        msg += "Ask  :  " + chnl.AskEnabled + "\n";
                        msg += "Comic  :  " + chnl.ComicModuleEnabled + "\n";
                        msg += "Gamertag  :  " + chnl.GamertagModuleEnabled + "\n";
                        msg += "MotD  :  " + chnl.MOTDEnabled + "\n";
                        msg += "Note : " + chnl.NoteModuleEnabled + "\n";
                        msg += "Quote  :  " + chnl.QuoteModuleEnabled + "\n";
                        msg += "Roll  :  " + chnl.RollEnabled + "\n";
                        msg += "Table  :  " + chnl.TableUnflipEnabled + "\n";
                        msg += "Twitter  :  " + chnl.TwitterModuleEnabled + "\n";
                        msg += "Politics : " + chnl.PoliticsEnabled + "\n";
                        msg += "Chat Battle : " + chnl.ChatBattleEnabled + "\n";
                        msg += "Chatty Mode : " + chnl.ChattyModeEnabled + "\n";
                        msg += "Markov Listener Enabled : " + chnl.MarkovListenerEnabled + "\n";
                        msg += "Meme Generator Enabled : " + chnl.MemeGenEnabled + "\n";
                        msg += "Cram Enabled: " + chnl.CramEnabled + "\n";
                        await e.Channel.SendMessage(msg);
                    }
                });

                cgb.CreateCommand("install")
                .Description("Returns a link that can be used to install this bot onto other servers.")
                .Do(async e =>
                {
                    await
                    e.Channel.SendMessage(
                        "https://discordapp.com/oauth2/authorize?&client_id=171093139052953607&scope=bot");
                });
            });
        }
示例#7
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;

            manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("note")
                .Description("Return the server note with the specified name")
                .Parameter("name", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "note", e.Channel.IsPrivate))
                    {
                        NoteRepository noteRepository =
                            Beta.ServerStateRepository.GetServerState(e.Server.Id).NoteRepository;
                        Note note = noteRepository.GetNote(e.GetArg("name"));
                        if (note != null)
                        {
                            await e.Channel.SendMessage(note.Text);
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                        else
                        {
                            await e.Channel.SendMessage("Sorry, I don't see a server note by the name of '" + e.GetArg("name") +
                                                        "', " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }
                    }
                });

                cgb.CreateCommand("notes")
                .Description("Return all server notes.")
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "note", e.Channel.IsPrivate))
                    {
                        NoteRepository noteRepository =
                            Beta.ServerStateRepository.GetServerState(e.Server.Id).NoteRepository;
                        string msg = "";

                        foreach (Note note in noteRepository.Notes)
                        {
                            msg += note.Name + ": " + note.Text + "\n";
                        }

                        await e.Channel.SendMessage(msg);
                    }
                });

                cgb.CreateCommand("deletenote")
                .Description("Delete the named server note.")
                .Parameter("text", ParameterType.Unparsed)
                .MinPermissions((int)PermissionLevel.ChannelModerator)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "note", e.Channel.IsPrivate))
                    {
                        if (
                            Beta.ServerStateRepository.GetServerState(e.Server.Id)
                            .NoteRepository.NoteExists(e.GetArg("text")))
                        {
                            await e.Channel.SendMessage("Ok, deleted that note for you, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "! Bye bye '" + e.GetArg("text") + "'.");

                            Beta.ServerStateRepository.GetServerState(e.Server.Id)
                            .NoteRepository.DeleteQuote(e.GetArg("text"));
                            Beta.ServerStateRepository.Save();
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                        }
                        else
                        {
                            await
                            e.Channel.SendMessage("Sorry, I was unable to find a note named '" + e.GetArg("text") +
                                                  "', " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }
                    }
                });

                cgb.CreateCommand("addnote")
                .Description("Add a server note by the specified name. $add Note Name|Whatever the note should say.")
                .Parameter("text", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "note", e.Channel.IsPrivate))
                    {
                        var args = e.GetArg("text").Split('|');
                        Console.WriteLine("Test");
                        NoteRepository temp = Beta.ServerStateRepository.GetServerState(e.Server.Id).NoteRepository;
                        temp.NoteExists(args[0]);
                        Console.WriteLine("Test2");
                        if (temp.NoteExists(args[0]))
                        {
                            await
                            e.Channel.SendMessage("Sorry, looks like we already have a note named '" + args[0] +
                                                  "' on this server, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }
                        else
                        {
                            Beta.ServerStateRepository.GetServerState(e.Server.Id)
                            .NoteRepository.AddNote(args[0], args[1], e.User.Name);

                            await
                            e.Channel.SendMessage(String.Format("Successfully added note '{0}', " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".",
                                                                args[0]));
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                            Beta.ServerStateRepository.Save();
                        }
                    }
                });
            });
        }
示例#8
0
        public override void Install(ModuleManager manager)
        {
            if (!Directory.Exists(memeplateFolder))
            {
                Directory.CreateDirectory(memeplateFolder);
            }
            if (!Directory.Exists(memeFolder))
            {
                Directory.CreateDirectory(memeFolder);
            }

            _manager = manager;
            _client  = manager.Client;
            Memes    = GetMemeList();

            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("meme")
                .Description("Generate your own meme on the fly! Examples:\n\n$meme \"Random|TopText|BottomText\n$meme YUNo|TopTextOnly\n\nSee $memelist for available Memes are just use Random!\"")
                .Parameter("memeArgs", ParameterType.Unparsed)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "meme", e.Channel.IsPrivate))
                    {
                        List <string> args = e.GetArg("memeArgs").Split('|').ToList <string>();
                        if (args.Count >= 2)
                        {
                            string memeName = args[0];
                            if (memeName.ToLower() == "random")
                            {
                                memeName = Memes.GetRandom();
                                Console.WriteLine(memeName);
                                Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                            }
                            string fileName = memeFolder + memeName + DateTime.Now.ToString("hhmmss") + ".png";

                            args.RemoveAt(0);
                            Image imageWithMemeText = PlaceImageText(args, memeName, e);
                            if (imageWithMemeText != null)
                            {
                                imageWithMemeText.Save(fileName, ImageFormat.Png);
                                await e.Channel.SendFile(fileName);
                                e.Message.Delete();
                                Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                            }
                        }
                        else
                        {
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }
                    }
                });

                cgb.CreateCommand("memelist")
                .Alias("listmemes")
                .Description("Have a list of available Memes PM'd to you")
                .Do(async e =>
                {
                    Memes          = GetMemeList();
                    string message = "Here are the memes I have available: \n";
                    foreach (string meme in Memes)
                    {
                        message += meme + "\n";
                    }
                    await e.User.SendMessage(message);
                });

                cgb.CreateCommand("addmeme")
                .Description("Add the specified link to an image as a meme, with the given name. Example:\n\n$addmeme \"OverlyAttachedGirlfriend|https://imgflip.com/s/meme/Overly-Attached-Girlfriend.jpg\"")
                .Parameter("text", ParameterType.Required)
                .MinPermissions((int)PermissionLevel.ChannelModerator)
                .Do(async e =>
                {
                    List <string> args = e.GetArg("text").Split('|').ToList <string>();
                    string memeName    = args[0];
                    string link        = args[1];
                    using (WebClient client = new WebClient())
                    {
                        try
                        {
                            client.DownloadFile(new Uri(link), memeplateFolder + memeName + ".png");
                        }
                        catch
                        {
                            await e.Channel.SendMessage("Sorry, I wasn't able to download that image. Check your link out, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + ".");
                            Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, -1);
                        }
                    }
                    await e.Channel.SendMessage("Ok, I've added that Memeplate for you, " + Nicknames.GetNickname(Beta.UserStateRepository.GetUserState(e.User.Id).Favorability) + "!");
                    Beta.UserStateRepository.ModifyUserFavorability(e.User.Id, 1);
                });
            });
        }
示例#9
0
        public override void Install(ModuleManager manager)
        {
            _manager = manager;
            _client  = manager.Client;


            _manager.CreateCommands("", cgb =>
            {
                cgb.MinPermissions((int)PermissionLevel.User);

                cgb.CreateCommand("create")
                .Description("Create a new character. Examples:\n\n $create [name] [PHY] [MEN] [VIT] [LUC]\n $create Test1 5 5 5 5\n$create \"Test 2\" 1 15 2 2")
                .Parameter("text", ParameterType.Multiple)
                .Do(async e =>
                {
                    if (Beta.CheckModuleState(e, "cram", e.Channel.IsPrivate))
                    {
                        if (!(e.Args.Count() == 5))
                        {
                            await e.Channel.SendMessage("Sorry, doesn't look like you've provided the right number of arguments.");
                        }
                        else
                        {
                            string name = e.Args[0];
                            int phy     = 0;
                            int men     = 0;
                            int vit     = 0;
                            int luc     = 0;
                            bool successfulConversion = false;
                            try
                            {
                                phy = Convert.ToInt32(e.Args[1]);
                                men = Convert.ToInt32(e.Args[2]);
                                vit = Convert.ToInt32(e.Args[3]);
                                luc = Convert.ToInt32(e.Args[4]);
                                successfulConversion = true;
                            }
                            catch
                            {
                                await e.Channel.SendMessage("Looks like one of your stats wasn't in number format, bub.");
                            }
                            if (successfulConversion)
                            {
                                if (ValidateScores(phy, men, vit, luc))
                                {
                                    CramManager.AddNewCharacter(name, phy, men, vit, luc, e.User.Id);
                                    await e.Channel.SendMessage("Ok, I've added that character for you!");
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Those scores aren't valid! Either they don't add up to 20, or you have a score above 15 or below 1.");
                                }
                            }
                        }
                    }
                });

                cgb.CreateCommand("listchars")
                .Description("Lists all of your characters across all games.")
                .Alias("listchar")
                .Do(async e =>
                {
                    string msg = "Character List\n";
                    msg       += "Character ID | Character Name | PHY | MEN | VIT | LUC | Cash | Skill Points\n";
                    msg       += CramManager.GetCharacters(e.User.Id.ToString());
                    await e.Channel.SendMessage(msg);
                });

                cgb.CreateCommand("selectchar")
                .Description("Select one of your characters by ID. You can check 'listchars' to get the ID. Example: \n\n$selectchar 2.")
                .Parameter("id", ParameterType.Required)
                .Do(async e =>
                {
                    int charId;
                    string characterName = "";
                    if (Int32.TryParse(e.GetArg("id"), out charId))
                    {
                        using (CharacterContext db = new CharacterContext())
                        {
                            Character selectedChar = db.Characters.FirstOrDefault(chr => chr.CharacterID == charId);
                            if (selectedChar != null)
                            {
                                if (selectedChar.UserId == e.User.Id.ToString())
                                {
                                    characterName             = selectedChar.Name;
                                    UserState usr             = Beta.UserStateRepository.GetUserState(e.User.Id);
                                    usr.SelectedCharacter     = charId;
                                    usr.SelectedCharacterName = characterName;
                                    await e.Channel.SendMessage("Awesome, I selected " + characterName + "!");
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Hey! THAT ISN'T YOUR CHARACTER!");
                                }
                            }
                            else
                            {
                                await e.Channel.SendMessage("Sorry, I don't see a character with that ID...");
                            }
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("That's not a digit, my dude.");
                    }
                });

                cgb.CreateCommand("selectedchar")
                .Description("Shows the currently selected character, if any.")
                .Do(async e =>
                {
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usr.SelectedCharacter != 0)
                    {
                        await e.Channel.SendMessage(usr.SelectedCharacter + " | " + usr.SelectedCharacterName);
                    }
                    else
                    {
                        await e.Channel.SendMessage("Looks like you don't actually have a character selected, buddy.");
                    }
                });

                cgb.CreateCommand("buy")
                .Description("Purchase an item. Provide the iteam id found from the 'listitems' command. Example: \n\n$buy 3.")
                .Parameter("id", ParameterType.Required)
                .Do(async e =>
                {
                    UserState usr = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usr.SelectedCharacter != 0)
                    {
                        int itemId;
                        if (Int32.TryParse(e.GetArg("id"), out itemId))
                        {
                            using (CharacterContext db = new CharacterContext())
                            {
                                List <Item> items = db.Items.ToList <Item>();
                                Item item         = items.FirstOrDefault(i => i.ItemID == itemId);
                                if (item != null)
                                {
                                    Character selectedCharacter = db.Characters.FirstOrDefault(c => c.CharacterID == usr.SelectedCharacter);
                                    if (selectedCharacter.Cash >= item.ItemCost)
                                    {
                                        selectedCharacter.Cash -= item.ItemCost;
                                        selectedCharacter.AddItem(item, 1);
                                        await e.Channel.SendMessage("Ok cool, thanks for the cash! I've added " + item.ItemName + " to your inventory!");
                                        db.SaveChanges();
                                    }
                                    else
                                    {
                                        await e.Channel.SendMessage("Sorry pal, you don't have enough cash.");
                                    }
                                }
                                else
                                {
                                    await e.Channel.SendMessage("Sorry, I don't see that item. You should check the 'listitems' command again to verify the ID!");
                                }
                            }
                        }
                        else
                        {
                            await e.Channel.SendMessage("That's not a digit, my dude!");
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("Looks like you don't actually have a character selected, buddy.");
                    }
                });

                cgb.CreateCommand("craminv")
                .Description("Lists the items in your inventory.")
                .Do(async e =>
                {
                    UserState usrState = Beta.UserStateRepository.GetUserState(e.User.Id);
                    if (usrState.SelectedCharacter != 0)
                    {
                        string msg = usrState.SelectedCharacterName + "'s Inventory\n";
                        msg       += "Item ID | Item Name | Item Description | Item Cost | Quantity";
                        msg       += CramManager.GetCharacterItems(usrState.SelectedCharacter);
                        await e.Channel.SendMessage(msg);
                    }
                });

                cgb.CreateCommand("listskills")
                .Description("Lists the generic list of skills.")
                .Do(async e =>
                {
                    string msg = "Skill List\n";
                    msg       += "Skill ID | Skill Name | Skill Description\n";
                    msg       += CramManager.GetSkills();
                    await e.Channel.SendMessage(msg);
                });

                cgb.CreateCommand("listitems")
                .Description("Lists the generic list of items..")
                .Do(async e =>
                {
                    string msg = "Item List\n";
                    msg       += "Item ID | Item Name | Item Description | Item Cost\n";
                    msg       += CramManager.GetItems();
                    await e.Channel.SendMessage(msg);
                });
            });
        }