Esempio n. 1
0
 private void OnCommandRecieved(BotWideCommandArguments args)
 {
     if (args.source == MESSAGESOURCE.TWITCH)
     {
         if (_timedMessages.Exists(p => p.twitchChannelName == args.channel))
         {
             _timedMessages.Find(p => p.twitchChannelName == args.channel).msgSinceLastused++;
         }
     }
     CommandResolve(args);
 }
Esempio n. 2
0
        }// EOF OnCommandReceived

        private async void InfoDump(BotChannel bChan, RolesSettings settings, BotWideCommandArguments args)
        {
            string message = $"```fix{System.Environment.NewLine}Admin/Broadcaster commands {System.Environment.NewLine}" +
                             $"{Program.CommandCharacter}roles < Arguments >{System.Environment.NewLine}{System.Environment.NewLine}" +
                             $"Arguments....{System.Environment.NewLine}" +
                             $"< none > -> this response{System.Environment.NewLine}" +
                             $"role add/edit/remove -> manage the roles that should be used.{System.Environment.NewLine}{System.Environment.NewLine}" +
                             $"Roles : {settings.Roles()}{System.Environment.NewLine}{System.Environment.NewLine}" +
                             $"Topics : {settings.TopicsList()}{System.Environment.NewLine}{System.Environment.NewLine}" +
                             $"Currently {settings.MarkedMessages.Count} messages is marked{System.Environment.NewLine}{System.Environment.NewLine}" +
                             $"Roles plugin is currently {(settings._active ? "active" : "inactive")}```";

            await SayOnDiscord(message, args.channelID);
        }
Esempio n. 3
0
        private async void OnCommandRecieved(BotWideCommandArguments args)
        {
            BotChannel bChan = await GetBotChannel(args);

            BotWideResponseArguments response = new BotWideResponseArguments(args);

            // TEMPORARY this should later move to a better suited plugin
            if (args.command == "juanage")
            {
                response.message = JuanAge();
                Respond(bChan, response);
                return;
            }


            if (args.isBroadcaster || args.isModerator || args.canManageMessages)
            {
                switch (args.command)
                {
                case "twitch":
                    // anything twitch has to go through discord
                    if (args.source != MESSAGESOURCE.DISCORD)
                    {
                        return;
                    }
                    // Clean command response
                    if (args.arguments.Count == 0)
                    {
                        if (bChan.TwitchChannelName == string.Empty)
                        {
                            response.message = $"There is no twitch channel tied to this Discord. Use \"{CMC}twitch channel <NameOfTwitchChannel>\" to tie a channel to this Discord.";
                        }
                        else
                        {
                            response.message = $"Currently this Discord is tied to the Twitch channel \"{bChan.TwitchChannelName}\"";
                        }
                        Respond(bChan, response);
                        return;
                    }
                    switch (args.arguments[0])
                    {
                    case "channel":
                        if (args.arguments.Count == 2)
                        {
                            TwitchLib.Api.V5.Models.Users.Users users = await Program.TwitchAPI.V5.Users.GetUserByNameAsync(args.arguments[1].ToLower());

                            if (users.Matches.Length != 1)
                            {
                                // Failed to look up twitch channel so notify and exit
                                response.message = "Sorry. Could not find that channel. Make sure you enter it correctly and try again.";
                                Respond(bChan, response);
                                return;
                            }
                            bChan.TwitchChannelName = args.arguments[1].ToLower();
                            bChan.TwitchChannelID   = users.Matches[0].Id;
                            bChan.TwitchAutojoin    = true;
                            response.message        = $"This Discord is now tied to the Twitch channel \"{bChan.TwitchChannelName}\".";
                            Program.Channels.ChannelSave(bChan);
                            if (Program.TwitchConnected)
                            {
                                await Program.Channels.JoinAllAutoJoinTwitchChannels();
                            }
                            else
                            {
                                response.message += " Not connected to Twitch so can't join the channel right now.";
                            }
                            Respond(bChan, response);
                        }
                        break;
                    }
                    break;

                case "pubsub":
                    // has to go through discord
                    if (args.source != MESSAGESOURCE.DISCORD)
                    {
                        return;
                    }
                    // Clean command response
                    if (args.arguments.Count == 0 || args.arguments[0] == "help")
                    {
                        response.message = PubSubHelpDump(bChan);
                        Respond(bChan, response);
                        return;
                    }
                    switch (args.arguments[0])
                    {
                    case "settoken":
                        if (args.arguments.Count == 2)
                        {
                            bChan.pubsubOauth = Cipher.Encrypt(args.arguments[1]);
                            Program.Channels.ChannelSave(bChan);
                            response.message = "Token set. Engaging PubSub Connection!";
                            Program.PubSubStart(bChan);
                            Program.DiscordRemoveMessage(Core.StringToUlong(args.channel), args.messageID);
                        }
                        else
                        {
                            response.message = "Did you forget the token?";
                        }
                        Respond(bChan, response);
                        return;

                    case "cleartoken":
                        bChan.pubsubOauth = string.Empty;
                        Program.Channels.ChannelSave(bChan);
                        response.message = "ClearToken";
                        Program.PubSubStop(bChan);
                        Respond(bChan, response);
                        return;

                    case "start":
                        Program.PubSubStart(bChan);
                        return;

                    case "stop":
                        Program.PubSubStop(bChan);
                        return;

                        /*case "status":
                         *  response.message = Program.PubSubStatus(bChan);
                         *  Respond(bChan, response);
                         *  return;
                         */
                    }
                    break;

                case "setadminchannel":
                    bChan.discordAdminChannel = Core.StringToUlong(args.channel);
                    Program.Channels.ChannelSave(bChan);
                    response.message = $"This is now set as the default adminchannel for this DiscordServer. This is needed to direct some important messages and notifications";
                    Respond(bChan, response);
                    return;
                }
            }
        }
Esempio n. 4
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;
                }
            }
        }
Esempio n. 5
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;
                }
            }
        }
Esempio n. 6
0
        private async void OnCommandReceived(BotWideCommandArguments args)
        {
            if (args.source != MESSAGESOURCE.DISCORD)
            {
                return;
            }
            if (!args.canManageMessages)
            {
                return;
            }

            BotChannel bChan = await GetBotChannel(args);

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

            BotWideResponseArguments response = new BotWideResponseArguments(args);

            if (args.command.ToLower() != "roles")
            {
                return;
            }
            // Helptext
            if (args.arguments.Count < 1)
            {
                InfoDump(bChan, settings, args);
                return;
            }
            // break down the command
            switch (args.arguments[0].ToLower())
            {
            case "on":
                settings._active = true;
                SaveBaseSettings(bChan, PLUGINNAME, settings);
                response.message = $"Roles is active.";
                Respond(bChan, response);
                break;

            case "off":
                settings._active = false;
                SaveBaseSettings(bChan, PLUGINNAME, settings);
                response.message = $"Roles is inactive.";
                Respond(bChan, response);
                break;

            case "mark":
                if (!settings._active)
                {
                    return;
                }
                if (args.arguments.Count < 3)
                {
                    response.message = $"Not enough arguments. Use \"{CMC}roles mark <DiscordMessageID> <topic>\" as syntax. Get The ID by rightclicking the message when your Discordclient has developer mode turned on in advanced settings.";
                    Respond(bChan, response);
                    return;
                }
                if (!settings.Topics.Exists(p => p.TopicName == args.arguments[2]))
                {
                    response.message = $"Can't find that topic. Doublecheck that it exist and you spelled it right.";
                    Respond(bChan, response);
                }
                ulong msgID = Core.StringToUlong(args.arguments[1]);
                if (settings.MarkedMessages.Exists(p => p.MessageID == msgID))
                {
                    response.message = $"That message has already been marked with a topic. To replace it you have to unmark it first.";
                    Respond(bChan, response);
                    return;
                }
                DiscordChannelMessage dMessage = await MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordGetMessage(response.discordChannel, msgID);

                if (dMessage == null)
                {
                    response.message = $"Can't find that message. Make sure I got access to channel and rights to manage messages in it.";
                    Respond(bChan, response);
                    return;
                }
                response.message = $"Marking that message with the topic \"{args.arguments[2]}\".";
                settings.MarkedMessages.Add(new MarkedMessage()
                {
                    MessageID = msgID, Topic = args.arguments[2], TimeStamp = Core.CurrentTime
                });

                await MarkMessage(bChan, settings, dMessage, args.arguments[2]);

                SaveBaseSettings(bChan, PLUGINNAME, settings);

                Respond(bChan, response);
                break;

            case "unmark":
                if (!settings._active)
                {
                    return;
                }
                if (args.arguments.Count < 2)
                {
                    response.message = $"Not enough arguments. Use \"{CMC}roles unmark <DiscordMessageID>\" as syntax. Get The ID by rightclicking the message when your Discordclient has developer mode turned on in advanced settings.";
                    Respond(bChan, response);
                    return;
                }
                ulong msgID2 = Core.StringToUlong(args.arguments[1]);
                if (!settings.MarkedMessages.Exists(p => p.MessageID == msgID2))
                {
                    response.message = $"That message isn't listed as marked.";
                    Respond(bChan, response);
                    return;
                }
                int removedNB = settings.MarkedMessages.RemoveAll(p => p.MessageID == msgID2);
                if (!settings.MarkedMessages.Exists(p => p.MessageID == msgID2))
                {
                    response.message = $"{removedNB} message has been unmarked.";
                    SaveBaseSettings(bChan, PLUGINNAME, settings);
                    Respond(bChan, response);
                    return;
                }
                else
                {
                    response.message = $"Something went wrong and message couldn't be unmarked. Try again and if it doesn't work complain to your mum.";
                    Respond(bChan, response);
                    return;
                }

            case "topic":
                if (!settings._active)
                {
                    return;
                }
                if (args.arguments.Count < 2)
                {
                    response.message = $"Topic is used to manage the topics. add/remove to create or delete topics. To add/remove roles to a topic use addrole/removerole.";
                    Respond(bChan, response);
                    return;
                }
                if (args.arguments[1].ToLower() == "add")
                {
                    if (args.arguments.Count < 3)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles topic add <TheTopicNameYouWant>\" as syntax";
                        Respond(bChan, response);
                        return;
                    }
                    if (TopicAdd(bChan, settings, args.arguments[2]))
                    {
                        response.message = $"Topic was added.";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Topic could not be added. Make sure it doens't already exist.";
                        Respond(bChan, response);
                    }
                }
                if (args.arguments[1].ToLower() == "remove")
                {
                    if (args.arguments.Count < 3)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles topic remove <NameofTopic>\" as syntax";
                        Respond(bChan, response);
                        return;
                    }
                    if (TopicRemove(bChan, settings, args.arguments[2]))
                    {
                        response.message = $"Topic was removed.";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Could not match topic.";
                        Respond(bChan, response);
                    }
                }



                if (args.arguments[1].ToLower() == "addrole")
                {
                    if (args.arguments.Count < 4)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles topic addrole <Topic> <RoleYouWantAdded>\" as syntax";
                        Respond(bChan, response);
                        return;
                    }
                    if (!MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordRoleExist(bChan, args.arguments[3]))
                    {
                        response.message = $"That role does not exist on this Discord. This matching is case sensitive.";
                        Respond(bChan, response);
                        return;
                    }
                    if (!settings.RoleTable.ContainsKey(args.arguments[3]))
                    {
                        response.message = $"That role exists on the Discord but needs to be registered with an emote for this plugin. See the \"{CMC}roles role\" command.";
                        Respond(bChan, response);
                        return;
                    }

                    if (TopicAddRole(bChan, settings, args.arguments[2], args.arguments[3]))
                    {
                        response.message = $"Role({args.arguments[3]}) was added to topic({args.arguments[2]}).";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Role({args.arguments[3]}) could not be added to Topic({args.arguments[2]}). Make sure you type it right.";
                        Respond(bChan, response);
                    }
                }

                if (args.arguments[1].ToLower() == "removerole")
                {
                    if (args.arguments.Count < 4)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles topic removerole <Topic> <RoleYouWantRemoved>\" as syntax";
                        Respond(bChan, response);
                        return;
                    }

                    if (!settings.RoleTable.ContainsKey(args.arguments[3]))
                    {
                        response.message = $"That role cant be matched with the known roles for this plugin. See the \"{CMC}roles role\" command.";
                        Respond(bChan, response);
                        return;
                    }

                    if (TopicRemoveRole(bChan, settings, args.arguments[2], args.arguments[3]))
                    {
                        response.message = $"Role({args.arguments[3]}) was removed from topic({args.arguments[2]}).";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Role({args.arguments[3]}) could not be removed Topic({args.arguments[2]}). Make sure you type it right.";
                        Respond(bChan, response);
                    }
                }

                break;

            case "role":
                if (!settings._active)
                {
                    return;
                }
                if (args.arguments.Count == 1)
                {
                    response.message = $"This manages the roles. Make sure they exist on the Discord side of things. Use add/remove like \"{CMC}roles role <add/remove>\"";
                    Respond(bChan, response);
                    return;
                }

                if (args.arguments[1].ToLower() == "add")
                {
                    if (args.arguments.Count < 4)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles role add <NameofDiscordrole> <NameofEmote>\" as syntax.";
                        Respond(bChan, response);
                        return;
                    }
                    if (!MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordRoleExist(bChan, args.arguments[2]))
                    {
                        response.message = $"That role({args.arguments[2]}) does not exist on this Discord. This matching is case sensitive.";
                        Respond(bChan, response);
                        return;
                    }
                    if (!Char.IsSurrogate(args.arguments[3], 0))
                    {
                        // Verify existence of custom emote
                        if (!MisfitBot_MKII.DiscordWrap.DiscordClient.DiscordEmoteExist(bChan, args.arguments[3]))
                        {
                            response.message = $"That emote does not exist. This matching is case sensitive.";
                            Respond(bChan, response);
                            return;
                        }
                    }
                    if (RoleAdd(bChan, settings, args.arguments[2], args.arguments[3]))
                    {
                        response.message = $"Role was added.";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Could not add role. Make sure role and emote isn't already used.";
                        Respond(bChan, response);
                    }
                }
                if (args.arguments[1].ToLower() == "remove")
                {
                    // TODO also remove from topics
                    if (args.arguments.Count < 3)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles role remove <NameofDiscordrole>\" as syntax.";
                        Respond(bChan, response);
                        return;
                    }
                    if (RoleRemove(bChan, settings, args.arguments[2]))
                    {
                        response.message = $"Role was removed.";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Could not match role.";
                        Respond(bChan, response);
                    }
                }
                if (args.arguments[1].ToLower() == "editemote")
                {
                    if (args.arguments.Count < 4)
                    {
                        response.message = $"Not enough arguments. Use \"{CMC}roles role editemote <RoleToEdit> <NewEmote>\" as syntax";
                        Respond(bChan, response);
                        return;
                    }
                    if (!settings.RoleTable.ContainsKey(args.arguments[2]))
                    {
                        response.message = $"Can't find that role. Make sure you enter it correctly and remember it is case sensitive.";
                        Respond(bChan, response);
                        return;
                    }
                    if (settings.RoleTable[args.arguments[2]] == args.arguments[3])
                    {
                        response.message = $"That is the already stored emote for that role. Baka!";
                        Respond(bChan, response);
                    }
                    if (RoleEdit(bChan, settings, args.arguments[2], args.arguments[3]))
                    {
                        response.message = $"The role {args.arguments[2]}'s emote was updated to {args.arguments[3]}.";
                        Respond(bChan, response);
                    }
                    else
                    {
                        response.message = $"Failed to change the emote.";
                        Respond(bChan, response);
                    }
                }
                break;
            }
        }// EOF OnCommandReceived
Esempio n. 7
0
 internal void RaiseOnCommandRecieved(BotWideCommandArguments args)
 {
     OnCommandReceived?.Invoke(args);
 }
Esempio n. 8
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;
            }
        }