示例#1
0
        private async void OnCommandRecieved(BotWideCommandArguments args)
        {
            BotChannel bChan = await GetBotChannel(args);

            if (bChan == null)
            {
                return;
            }
            await DBVerify(bChan);

            InsultSettings settings = await Settings <InsultSettings>(bChan, PluginName);

            BotWideResponseArguments response = new BotWideResponseArguments(args);

            if (args.command.ToLower() == "insult" && settings._active)
            {
                string pickedLine = dbStrings.GetRandomLine(bChan, "INSULT");
                response.message      = pickedLine;
                response.parseMessage = true;
                response.victim       = args.user;
                Respond(bChan, response);
            }
            if (!args.isModerator && !args.isBroadcaster && !args.canManageMessages)
            {
                // No access below
                return;
            }
            if (args.command.ToLower() == "insults")
            {
                // Blank insults response here
                if (args.arguments.Count == 0)
                {
                    if (args.source == MESSAGESOURCE.DISCORD)
                    {
                        Discord.EmbedFooterBuilder footer = new Discord.EmbedFooterBuilder {
                            Text = $"The plugin is currently {(settings._active ? "active" : "inactive")} here."
                        };

                        Discord.EmbedBuilder embedded = new Discord.EmbedBuilder {
                            Title       = "Plugin: Insults ",
                            Description = HelpText(settings),
                            Color       = Discord.Color.DarkOrange,
                            Footer      = footer
                        };

                        await SayEmbedOnDiscord(args.channelID, embedded.Build());

                        return;
                    }
                    if (args.source == MESSAGESOURCE.TWITCH)
                    {
                        response.message = $"The plugin is currently {(settings._active ? "active" : "inactive")} here.";
                        Respond(bChan, response);
                        return;
                    }
                }
                // resolve subcommands
                switch (args.arguments[0])
                {
                case "off":
                    settings._active = false;
                    SaveBaseSettings(bChan, PluginName, settings);
                    response.message = $"Insults is inactive.";
                    Respond(bChan, response);
                    break;

                case "on":
                    settings._active = true;
                    SaveBaseSettings(bChan, PluginName, settings);
                    response.message = $"Insults is active.";
                    Respond(bChan, response);
                    break;

                case "add":
                    if (args.source == MESSAGESOURCE.TWITCH)
                    {
                        return;
                    }
                    if (args.arguments.Count <= 1)
                    {
                        response.message = "You need to have line after the add. Use [VICTIM] as replacement of the user's name.";
                        Respond(bChan, response);
                        return;
                    }
                    args.arguments.RemoveAt(0);
                    string line = string.Empty;
                    foreach (string part in args.arguments)
                    {
                        line += " " + part;
                    }
                    line = line.Trim();
                    dbStrings.SaveNewLine(bChan, "INSULT", line);
                    response.message = $"Added one more line for the Insult plugin.";
                    Respond(bChan, response);
                    break;

                case "use":
                    if (args.source == MESSAGESOURCE.TWITCH)
                    {
                        return;
                    }
                    if (args.arguments.Count <= 1)
                    {
                        response.message = "You need to give a valid ID. Check the List command to see ID for the lines in the database.";
                        Respond(bChan, response);
                        return;
                    }
                    int id = -1;
                    int.TryParse(args.arguments[1], out id);
                    if (id < 1)
                    {
                        response.message = "You need to give a valid ID. That ID couldn't be used.";
                        Respond(bChan, response);
                        return;
                    }
                    DBString entry = await dbStrings.GetStringByID(bChan, id);

                    if (entry == null)
                    {
                        response.message = "That ID didn't match anything I could find. Doublecheck it.";
                        Respond(bChan, response);
                        return;
                    }
                    DBString edited = new DBString(entry._id, !entry._inuse, entry._topic, entry._text);
                    if (dbStrings.SaveEditedLineByID(bChan, edited))
                    {
                        response.message = "Entry updated.";
                    }
                    else
                    {
                        response.message = "Failed to update entry.";
                    }
                    Respond(bChan, response);
                    break;

                case "remove":
                    if (args.arguments.Count <= 1)
                    {
                        response.message = "You need to give a valid ID. Check the List command to see ID for the lines in the database.";
                        Respond(bChan, response);
                        return;
                    }
                    int id2 = -1;
                    int.TryParse(args.arguments[1], out id2);
                    if (id2 < 1)
                    {
                        response.message = "You need to give a valid ID. That ID couldn't be used.";
                        Respond(bChan, response);
                        return;
                    }
                    DBString entry2 = await dbStrings.GetStringByID(bChan, id2);

                    if (entry2 == null)
                    {
                        response.message = "That ID didn't match anything I could find. Doublecheck it.";
                        Respond(bChan, response);
                        return;
                    }
                    if (entry2._inuse)
                    {
                        response.message = $"Only entries that is not in use can be deleted. Use \"{CMC}insults use <ID>\" to toggle the inuse flag on entries.";
                        Respond(bChan, response);
                        return;
                    }
                    // Remove the actual entry
                    if (dbStrings.DeleteEntry(bChan, id2))
                    {
                        response.message = $"Entry {id2} deleted.";
                        Respond(bChan, response);
                        return;
                    }
                    response.message = $"Failed to delete line {id2} for some reason.";
                    Respond(bChan, response);
                    break;

                case "list":
                    if (args.source != MESSAGESOURCE.DISCORD)
                    {
                        return;
                    }
                    if (args.arguments.Count == 1)
                    {
                        await ListLinesFromDB(bChan, args.channelID, 0);

                        return;
                    }
                    int page = 0;
                    int.TryParse(args.arguments[1], out page);
                    if (page <= 0)
                    {
                        page = 1;
                    }

                    await ListLinesFromDB(bChan, args.channelID, page - 1);

                    break;
                }
            }
        }
示例#2
0
        private async void CommandResolve(BotWideCommandArguments args)
        {
            if (args.command.ToLower() != "couch" && args.command.ToLower() != "seat" && args.command.ToLower() != "seats")
            {
                return;
            }
            BotChannel bChan = await GetBotChannel(args);

            if (bChan == null)
            {
                return;
            }
            if (args.user == null)
            {
                return;
            }
            // Prep response instance
            BotWideResponseArguments response = new BotWideResponseArguments(args);

            // For Couch we don't go further if we don't have a twitch channel tied to the discord guild
            if (bChan.TwitchChannelName == string.Empty && args.arguments.Count == 0)
            {
                response.message = "There is no twitch channel to run a couch in.";
                Respond(bChan, response);
                return;
            }

            CouchSettings settings = await Settings <CouchSettings>(bChan, PLUGINNAME);

            if (!settings._couches.ContainsKey(bChan.Key))
            {
                settings._couches[bChan.Key] = new CouchEntry();
            }
            switch (args.command.ToLower())
            {
            case "couch":
                // Broadcaster and Moderator commands
                if (args.isModerator || args.isBroadcaster || args.canManageMessages)
                {
                    // Check so we are connected to the twitch channel
                    if (!Program.Channels.CheckIfInTwitchChannel(bChan.TwitchChannelName))
                    {
                        response.message = "Couch needs a twitch channel connection. See \"twitch\" command.";
                        Respond(bChan, response);
                        return;
                    }
                    if (args.arguments.Count == 0)
                    {
                        if (args.source == MESSAGESOURCE.DISCORD)
                        {
                            string message = $"```fix{System.Environment.NewLine}Admin/Broadcaster commands {System.Environment.NewLine}" +
                                             $"{Program.CommandCharacter}couch < Arguments >{System.Environment.NewLine}{System.Environment.NewLine}" +
                                             $"Arguments....{System.Environment.NewLine}" +
                                             $"< none > ->responds current settings{System.Environment.NewLine}" +
                                             $"open -> Manually resets and open the couch.{System.Environment.NewLine}" +
                                             $"on/off -> Turns plugin on or off for the channel.{System.Environment.NewLine}" +
                                             $"size # -> Sets the number of seats between 1 and 40.{System.Environment.NewLine}" +
                                             $"greet # -> Sets the number of seated needed in stats for a greeting when a user joins the twitch channel.{System.Environment.NewLine}" +
                                             $"time # -> Sets the time in seconds the couch will stay open.{System.Environment.NewLine}{System.Environment.NewLine}" +
                                             $"Discord only arguments(make sure adminchannel is set in adminplugin){System.Environment.NewLine}" +
                                             $"addsuccess < text > Text being the line returned. Use [USER] in text where username should be.{System.Environment.NewLine}" +
                                             $"addfail < text >{System.Environment.NewLine}" +
                                             $"addgreet < text >{System.Environment.NewLine}" +
                                             $"addincident < text >{System.Environment.NewLine}" +
                                             $"list / list # -> Shows stored lines by page.{System.Environment.NewLine}" +
                                             $"use # -> Toggles the inuse flag for the line with given ID.{System.Environment.NewLine}" +
                                             $"delete # -> Deletes the line with the ID if inuse flag is false. As in not in use.{System.Environment.NewLine}" +
                                             System.Environment.NewLine + System.Environment.NewLine +
                                             $"User commands{System.Environment.NewLine}" +
                                             $"{Program.CommandCharacter}seat -> When couch open it responds with success of fail message.{System.Environment.NewLine}" +
                                             $"{Program.CommandCharacter}seats -> User stats rundown.{System.Environment.NewLine}```";
                            await SayOnDiscord(message, args.channelID);
                        }
                        if (settings._active)
                        {
                            response.message = $"Couch is active. {settings.couchsize} seats. Greetlimit is {settings.potatoGreeting}. Open time is {settings.openTime}";
                            Respond(bChan, response);
                        }
                        else
                        {
                            response.message = $"Couch is inactive. {settings.couchsize} seats. Greetlimit is {settings.potatoGreeting}. Open time is {settings.openTime}";
                            Respond(bChan, response);
                        }
                        return;
                    }
                    switch (args.arguments[0].ToLower())
                    {
                    case "addfail":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "FAIL", args.arguments);
                        }
                        break;

                    case "addgreet":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "GREET", args.arguments);
                        }
                        break;

                    case "addincident":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "INCIDENT", args.arguments);
                        }
                        break;

                    case "addsuccess":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "SUCCESS", args.arguments);
                        }
                        break;

                    case "addtardy":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "TARDY", args.arguments);
                        }
                        break;

                    case "addshakes":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "SHAKES", args.arguments);
                        }
                        break;

                    case "addshakef":
                        if (args.arguments.Count >= 2)
                        {
                            await AddLine(bChan, "SHAKEF", args.arguments);
                        }
                        break;

                    case "close":
                        CloseCouch(bChan, settings);
                        break;

                    case "dbgreet":
                        response.message      = dbStrings.GetRandomLine(bChan, "GREET");
                        response.parseMessage = true;
                        Respond(bChan, response);
                        break;

                    case "delete":
                        if (args.arguments.Count == 1)
                        {
                            return;
                        }
                        int id = -1;
                        int.TryParse(args.arguments[1], out id);
                        if (id <= 0)
                        {
                            return;
                        }
                        await DeleteEntry(bChan, args.channelID, id);

                        break;

                    case "greet":
                        if (args.arguments.Count == 2)
                        {
                            int greet = settings.potatoGreeting;
                            int.TryParse(args.arguments[1], out greet);
                            if (greet > 0 && greet <= 100 && greet != settings.potatoGreeting)
                            {
                                settings.potatoGreeting = greet;
                                response.message        = $"Couch greeting limit is now {settings.potatoGreeting}.";
                                Respond(bChan, response);
                                await SayOnDiscordAdmin(bChan, $"{args.userDisplayName} changed the Couch Greetlimit setting to {settings.potatoGreeting}.");

                                SaveBaseSettings(bChan, PLUGINNAME, settings);
                            }
                            else
                            {
                                response.message = $"Couch greeting limit has to be more than 0 and max 100.";
                                Respond(bChan, response);
                            }
                        }
                        break;

                    case "off":
                        settings._active = false;
                        SaveBaseSettings(bChan, PLUGINNAME, settings);
                        response.message = $"Couch is inactive. {settings.couchsize} seats. Greetlimit is {settings.potatoGreeting}. Open time is {settings.openTime}";
                        Respond(bChan, response);
                        break;

                    case "on":
                        settings._active = true;
                        SaveBaseSettings(bChan, PLUGINNAME, settings);
                        response.message = $"Couch is active. {settings.couchsize} seats. Greetlimit is {settings.potatoGreeting}. Open time is {settings.openTime}";
                        Respond(bChan, response);
                        break;

                    case "open":
                        if (!settings._active)
                        {
                            return;
                        }
                        OpenCouch(bChan, settings);
                        break;

                    /*  TODO never look at this again!!
                     * case "restore":
                     *  bool removed = await dbStrings.TableDrop(bChan);
                     *  if (removed)
                     *  {
                     *      await SayOnDiscordAdmin(bChan, "Removed all current line data from the database.");
                     *  }
                     *  else
                     *  {
                     *      await SayOnDiscordAdmin(bChan, "Couldn't remove anything from the database.");
                     *  }
                     *  break;*/
                    case "rock":
                    case "shake":
                        await ShakeCouch(bChan, settings);

                        break;

                    case "size":
                        if (args.arguments.Count == 2)
                        {
                            int seats = settings.couchsize;
                            int.TryParse(args.arguments[1], out seats);
                            if (seats > 0 && seats <= 100 && seats != settings.couchsize)
                            {
                                settings.couchsize = seats;
                                response.message   = $"Couch now has {settings.couchsize} seats.";
                                Respond(bChan, response);
                                await SayOnDiscordAdmin(bChan, $"{args.userDisplayName} changed the Couch size to {settings.couchsize}.");

                                SaveBaseSettings(bChan, PLUGINNAME, settings);
                            }
                            else
                            {
                                response.message = $"Couch size limit has to be more than 0 and max 100.";
                                Respond(bChan, response);
                            }
                        }
                        break;

                    case "time":
                        if (args.arguments.Count == 2)
                        {
                            int timer = settings.openTime;
                            int.TryParse(args.arguments[1], out timer);
                            if (timer > 0 && timer <= 10000 && timer != settings.openTime)
                            {
                                settings.openTime = timer;
                                response.message  = $"Couch time limit is now {settings.openTime} seconds.";
                                Respond(bChan, response);
                                await SayOnDiscordAdmin(bChan, $"{args.user} changed the Couch open time limit setting to {settings.openTime} seconds.");

                                SaveBaseSettings(bChan, PLUGINNAME, settings);
                            }
                            else
                            {
                                response.message = $"Couch time limit has to be more than 0 and max 10000 seconds.";
                                Respond(bChan, response);
                            }
                        }
                        break;

                    case "use":
                        if (args.arguments.Count == 1)
                        {
                            return;
                        }
                        id = -1;
                        int.TryParse(args.arguments[1], out id);
                        if (id <= 0)
                        {
                            return;
                        }
                        await ToggleInUse(bChan, id);

                        break;

                    case "who":
                        if (!settings._active || args.source != MESSAGESOURCE.DISCORD)
                        {
                            return;
                        }
                        response.message = GetAllSittersAsString(bChan, settings);
                        Respond(bChan, response);
                        break;

                    case "list":
                        if (args.source != MESSAGESOURCE.DISCORD)
                        {
                            return;
                        }
                        if (args.arguments.Count == 1)
                        {
                            await ListLinesFromDB(bChan, args.channelID, 0);

                            return;
                        }
                        int page = 0;
                        int.TryParse(args.arguments[1], out page);
                        if (page <= 0)
                        {
                            page = 1;
                        }

                        await ListLinesFromDB(bChan, args.channelID, page - 1);

                        break;
                    }
                }
                break;

            // User Commands
            case "seat":
                if (!settings._couches[bChan.Key].couchOpen || !settings._active)
                {
                    return;
                }
                // To late
                if (Core.CurrentTime > settings._couches[bChan.Key].lastActivationTime + settings.openTime)
                {
                    // only give feedback a specified count on fails
                    if (settings.failCount <= settings.maxFails)
                    {
                        Respond(bChan, new BotWideResponseArguments(args)
                        {
                            source         = args.source,
                            twitchChannel  = bChan.TwitchChannelName,
                            discordChannel = bChan.discordAdminChannel,
                            user           = args.user,
                            victim         = null,
                            message        = dbStrings.GetRandomLine(bChan, "TARDY"),
                            parseMessage   = true
                        });
                        settings.failCount++;
                        SaveBaseSettings(bChan, PLUGINNAME, settings);
                    }
                    return;
                }
                if (settings._couches[bChan.Key].TwitchUsernames.Contains(args.userDisplayName))
                {
                    return;
                }

                if (settings._couches[bChan.Key].TwitchUsernames.Count < settings.couchsize)
                {
                    if (settings._couches[bChan.Key].TwitchUsernames.Count != 0)
                    {
                        if (RollIncident(15))
                        {
                            string rngSitter = GetRNGSitter(bChan, settings);
                            if (rngSitter != null)
                            {
                                UserEntry victim = await Program.Users.GetUserByTwitchDisplayName(rngSitter);

                                if (victim != null)
                                {
                                    settings._couches[bChan.Key].TwitchUsernames.RemoveAll(p => p == victim._twitchUsername);
                                    if (!await UserStatsExists(bChan.Key, args.user.Key))
                                    {
                                        UserStatsCreate(bChan.Key, args.user.Key);
                                    }
                                    CouchUserStats userStats1 = await UserStatsRead(bChan.Key, args.user.Key);

                                    userStats1.CountSeated++;
                                    UserStatsSave(bChan, userStats1);

                                    if (!await UserStatsExists(bChan.Key, victim.Key))
                                    {
                                        UserStatsCreate(bChan.Key, args.user.Key);
                                    }
                                    CouchUserStats markUserStats = await UserStatsRead(bChan.Key, victim.Key);

                                    markUserStats.CountBooted++;
                                    UserStatsSave(bChan, markUserStats);

                                    response.victim       = victim;
                                    response.message      = dbStrings.GetRandomLine(bChan, "INCIDENT");
                                    response.parseMessage = true;
                                    Respond(bChan, response);

                                    SaveBaseSettings(bChan, PLUGINNAME, settings);
                                }
                            }
                        }
                    }
                    if (!await UserStatsExists(bChan.Key, args.user.Key))
                    {
                        UserStatsCreate(bChan.Key, args.user.Key);
                    }
                    CouchUserStats userStats = await UserStatsRead(bChan.Key, args.user.Key);

                    userStats.CountSeated++;
                    UserStatsSave(bChan, userStats);
                    settings._couches[bChan.Key].TwitchUsernames.Add(args.userDisplayName);

                    Respond(bChan, new BotWideResponseArguments(args)
                    {
                        message      = dbStrings.GetRandomLine(bChan, "SUCCESS"),
                        parseMessage = true
                    });

                    SaveBaseSettings(bChan, PLUGINNAME, settings);
                }
                else
                {
                    Program.TwitchSayMessage(args.channel,
                                             dbStrings.GetRandomLine(bChan, "FAIL").Replace("[USER]", args.user._twitchDisplayname)
                                             );
                    settings.failCount++;
                    SaveBaseSettings(bChan, PLUGINNAME, settings);
                }
                break;

            case "seats":
                CouchUserStats cStats = await GetUserCouchStats(bChan.Key, args.user.Key);

                Program.TwitchSayMessage(args.channel,
                                         $"{args.user._twitchDisplayname}, you have sat in couch {cStats.CountSeated} times. {cStats.CountBooted} times you fell off."
                                         );
                break;
            }
        }