Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 2
0
        private async void OnCommandRecieved(BotWideCommandArguments args)
        {
            BotChannel bChan = await GetBotChannel(args);

            if (bChan == null)
            {
                return;
            }
            QueueSettings settings = await Settings <QueueSettings>(bChan, PluginName);

            BotWideResponseArguments response = new BotWideResponseArguments(args);

            if (settings._active && args.source == MESSAGESOURCE.TWITCH && (args.command.ToLower() == "addqueue" || args.command.ToLower() == "aq"))
            {
                QueueUp(bChan, args.userDisplayName);
                return;
            }
            if (settings._active && args.source == MESSAGESOURCE.TWITCH && (args.command.ToLower() == "leavequeue" || args.command.ToLower() == "lq"))
            {
                if (QueueLeave(bChan, args.userDisplayName))
                {
                    response.message      = $"{args.userDisplayName} left the queue";
                    response.parseMessage = true;
                    response.victim       = args.user;
                    Respond(bChan, response);
                }
                return;
            }

            if (!args.isModerator && !args.isBroadcaster && !args.canManageMessages)
            {
                // No access below
                return;
            }
            if (args.command.ToLower() == "queue")
            {
                // Blank queue 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.{(HasActiveQueue(bChan) ? $" {QueuedUserCount(bChan)} in queue." : "")}"
                        };

                        Discord.EmbedBuilder embedded = new Discord.EmbedBuilder
                        {
                            Title       = "Plugin: Queue ",
                            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.{(HasActiveQueue(bChan) ? $" {QueuedUserCount(bChan)} in queue." : "")}";
                        Respond(bChan, response);
                        return;
                    }
                }
                // resolve subcommands
                switch (args.arguments[0])
                {
                case "off":
                    settings._active = false;
                    SaveBaseSettings(bChan, PluginName, settings);
                    response.message = $"Queue is inactive.";
                    Respond(bChan, response);
                    break;

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

                case "next":
                    if (settings._active)
                    {
                        response.message = NextInQueue(bChan);
                        Respond(bChan, response);
                        if (response.source == MESSAGESOURCE.DISCORD && bChan.TwitchChannelName != string.Empty)
                        {
                            Program.TwitchSayMessage(bChan.TwitchChannelName, response.message);
                        }
                    }
                    break;

                case "reset":
                    if (settings._active)
                    {
                        CreateQueue(bChan, settings);
                        response.message = "Queue reset";
                        Respond(bChan, response);
                        if (response.source == MESSAGESOURCE.DISCORD && bChan.TwitchChannelName != string.Empty)
                        {
                            Program.TwitchSayMessage(bChan.TwitchChannelName, response.message);
                        }
                    }
                    break;

                case "start":
                    if (settings._active)
                    {
                        CreateQueue(bChan, settings);
                        response.message = $"Queue started";
                        Respond(bChan, response);
                        if (response.source == MESSAGESOURCE.DISCORD && bChan.TwitchChannelName != string.Empty)
                        {
                            Program.TwitchSayMessage(bChan.TwitchChannelName, response.message);
                        }
                    }
                    break;

                case "stop":
                    if (settings._active)
                    {
                        StopQueue(bChan);
                        response.message = $"Queue stopped.";
                        Respond(bChan, response);
                        if (response.source == MESSAGESOURCE.DISCORD && bChan.TwitchChannelName != string.Empty)
                        {
                            Program.TwitchSayMessage(bChan.TwitchChannelName, response.message);
                        }
                    }
                    break;
                }
            }
        }