public SoundEntry(string Command, TwitchRightsEnum Requirement, string[] Files, string Description, DateTime DateAdded)
 {
     this.Command     = Command;
     this.Requirement = Requirement;
     this.File        = Files;
     this.Description = Description;
     this.DateAdded   = DateAdded;
 }
 public SoundEntry(string Command, TwitchRightsEnum Requirement, string File, DateTime DateAdded)
 {
     //This is actually not used, but I wrote it, so whatever
     this.Command     = Command;
     this.Requirement = Requirement;
     this.File        = new string[1] {
         File
     };
     Description    = "";
     this.DateAdded = DateAdded;
 }
 public static TwitchRightsEnum ToTwitchRights(this int Number)
 {
     Number += 1;
     try
     {
         TwitchRightsEnum right = (TwitchRightsEnum)Number;
         return(right);
     }
     catch
     {
         return(TwitchRightsEnum.Disabled);
     }
 }
Exemplo n.º 4
0
 public static SoundEntry GetQuickSoundEntry(this XmlDocument xmlDoc, XmlNode node)
 {
     try
     {
         string           tmpCommand     = node.Name;
         string[]         tmpSounds      = node.Sui_GetAttributeValue(xmlDoc, varSounds, "").Split(';');
         TwitchRightsEnum tmpRequirement = node.Sui_GetAttributeValue(xmlDoc, varRequirement, TwitchRightsEnum.Disabled.ToString()).ToTwitchRights();
         string           tmpDescription = node.Sui_GetAttributeValue(xmlDoc, varDescription, "");
         DateTime         dateAdded      = node.Sui_GetAttributeValue(xmlDoc, varDateAdded, DateTime.UtcNow.ToString()).ToDateTimeSafe();
         return(new SoundEntry(tmpCommand, tmpRequirement, tmpSounds, tmpDescription, dateAdded));
     }
     catch
     {
         return(new SoundEntry());
     }
 }
        private string GetHTMLColor(TwitchRightsEnum twitchRightsEnum)
        {
            switch (twitchRightsEnum)
            {
            case TwitchRightsEnum.Admin:
                return("#FF0000");

            case TwitchRightsEnum.Mod:
                return("#00FF00");

            case TwitchRightsEnum.TrustedSub:
                return("#F0F0FF");

            case TwitchRightsEnum.Public:
                return("#FFFF90");

            default:
                return("#0000FF");
            }
        }
        public static SoundEntry ToSoundEntry(this TreeNode node)
        {
            if (node.Name == DB_Editor.NodeNameEntry)
            {
                string           Command     = node.Text;
                TwitchRightsEnum Right       = node.Nodes[DB_Editor.NodeNameRequirements].Text.ToTwitchRights();
                string[]         Files       = new string[node.Nodes[DB_Editor.NodeNameFiles].Nodes.Count];
                string           Description = node.Nodes[DB_Editor.NodeDescription].Text;
                DateTime         DateAdded   = node.Nodes[DB_Editor.NodeNameDateAdded].Text.ToDateTimeSafe();

                for (int i = 0; i < Files.Length; i++)
                {
                    Files[i] = node.Nodes[DB_Editor.NodeNameFiles].Nodes[i].Text;
                }

                return(new SoundEntry(Command, Right, Files, Description, DateAdded));
            }
            else
            {
                return(new SoundEntry());
            }
        }
        public static List <SoundEntry> ImportFiles()
        {
            List <SoundEntry> soundEntries = new List <SoundEntry>();
            DialogResult      res          = MessageBox.Show("Do you really want to import sounds from Botnak?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.No)
            {
                return(soundEntries);
            }

            string botnakDir = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Botnak", "sounds.txt");

            if (!File.Exists(botnakDir))
            {
                return(soundEntries);
            }

            var lines = File.ReadAllLines(botnakDir);

            foreach (var line in lines)
            {
                if (line.Count(x => x == ',') >= 2)
                {
                    string[]         helper      = line.Split(',');
                    string           command     = helper[0];
                    TwitchRightsEnum requirement = RequirementToInt(helper[1]).ToTwitchRights();
                    string[]         files       = new string[helper.Length - 2];
                    for (int i = 0; i < helper.Length - 2; i++)
                    {
                        files[i] = helper[i + 2];
                    }
                    soundEntries.Add(new SoundEntry(command, requirement, files, "", DateTime.UtcNow));
                }
            }
            return(soundEntries);
        }
Exemplo n.º 8
0
        private bool RunBot(ReadMessage formattedMessage)
        {
            FormattedMessage = formattedMessage;

            switch (FormattedMessage.msgType)
            {
            case MessageType.TTSReward:
            {
                parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.SoundCommand);

                if (programSettings.TTSLogic == TTSLogic.Restricted)
                {
                    if (FormattedMessage.rights >= programSettings.TTSRoleRequirement)
                    {
                        if (SndDB.PlayTTS(formattedMessage.user, formattedMessage.message, true))
                        {
                            irc.UpdateRedemptionStatus(formattedMessage, KrakenConnections.RedemptionStates.FULFILLED);
                        }
                        else
                        {
                            irc.UpdateRedemptionStatus(formattedMessage, KrakenConnections.RedemptionStates.CANCELED);
                        }
                        return(true);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    SndDB.PlayTTS(formattedMessage.user, formattedMessage.message, true);
                    return(true);
                }
            }

            case MessageType.SoundReward:
            {
                parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.SoundCommand);
                string text = formattedMessage.message.ToLower();
                if (text.StartsWith(PrefixChar.ToString()))
                {
                    text = text.Remove(0, 1);
                }

                TwitchRightsEnum privilage = formattedMessage.rights;


                if (SndDB.PlaySoundIfExists(formattedMessage.user, text, privilage, true))
                {
                    irc.UpdateRedemptionStatus(formattedMessage, KrakenConnections.RedemptionStates.FULFILLED);
                }
                else
                {
                    irc.UpdateRedemptionStatus(formattedMessage, KrakenConnections.RedemptionStates.CANCELED);
                }

                return(true);
            }

            default:
                if (!formattedMessage.message.StartsWith(PrefixChar.ToString()) || irc.ignorelist.Contains(formattedMessage.user))
                {
                    parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.Generic);
                    //literally nothing else happens in your code if this is false
                    return(true);
                }
                else
                {
                    TwitchRightsEnum privilage = formattedMessage.rights;
                    string           text      = formattedMessage.message.Remove(0, 1).ToLower();

                    //Mod Commands
                    if (formattedMessage.rights >= TwitchRightsEnum.Mod || irc.moderators.Contains(formattedMessage.user))
                    {
                        if (text == "volume" || text.StartsWith("volume "))
                        {
                            parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.ModCommand);
                            SndDB.ChangeVolumeIRC(irc, text, parent);
                            return(true);
                        }

                        if (text == "delay" || text.StartsWith("delay "))
                        {
                            parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.ModCommand);
                            SndDB.ChangeDelay(irc, text);
                            return(true);
                        }

                        if (text == "stopallsounds")
                        {
                            parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.ModCommand);
                            SndDB.Stopallsounds();
                            return(true);
                        }

                        if (text.StartsWith("removesound "))
                        {
                            parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.ModCommand);
                            SndDB.RemoveSound(irc, text);
                            return(true);
                        }

                        if (text.StartsWith("suboverride"))
                        {
                            parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.ModCommand);
                            SndDB.ChangeSubOverride(irc, text);
                            return(true);
                        }
                    }

                    //TTS
                    if (text.StartsWith("tts "))
                    {
                        parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.SoundCommand);

                        if (programSettings.TTSLogic == TTSLogic.RewardIDAndCommand)
                        {
                            if (formattedMessage.rights >= TwitchRightsEnum.Mod)
                            {
                                SndDB.PlayTTS(formattedMessage.user, formattedMessage.message.Split(new char[] { ' ' }, 2)[1]);
                            }
                            return(true);
                        }

                        return(true);
                    }                             //SoundPlayback
                    else
                    {
                        if (programSettings.SoundRedemptionLogic == SoundRedemptionLogic.Legacy || privilage == TwitchRightsEnum.Admin)
                        {
                            parent.ThreadSafeAddPreviewText(formattedMessage.user + ": " + formattedMessage.message, LineType.SoundCommand);
                            SndDB.PlaySoundIfExists(formattedMessage.user, text, privilage);
                        }
                    }

                    return(true);
                }
            }
        }
        public bool PlaySoundIfExists(string user, string cmd, TwitchRightsEnum userLevel, bool IgnoreCooldowns = false)
        {
            if (user == null)
            {
                return(false);
            }

            //Iterate through existing sound players
            for (int i = SoundPlayererStack.Count - 1; i >= 0; i--)
            {
                //Dispose of the ones which finished playing
                if (SoundPlayererStack[i].DonePlaying())
                {
                    SoundPlayererStack[i].Dispose();
                    SoundPlayererStack.RemoveAt(i);
                }
            }

            //Check if our db has a user and if not add him
            if (!userDB.ContainsKey(user))
            {
                userDB.Add(user, DateTime.MinValue);
            }


            //check user cooldown
            if (userDB[user] + TimeSpan.FromSeconds(delay) < DateTime.Now || IgnoreCooldowns)
            {
                //iterate between all files in a sound list
                for (int i = 0; i < soundlist.Count; i++)
                {
                    //if sound is found
                    if (soundlist[i].GetCommand() == cmd)
                    {
                        //Check right requirements
                        if (userLevel >= soundlist[i].GetRequirement() && soundlist[i].GetRequirement() != TwitchRightsEnum.Disabled)
                        {
                            string filename = soundlist[i].GetFile(rng);
                            for (int j = 0; j < SoundPlayererStack.Count; j++)
                            {
                                //Just so we don't play the same sounds at the same time
                                if (filename == SoundPlayererStack[j].fullFileName)
                                {
                                    return(false);
                                }
                            }
                            //Sound is found, is not played allocate a new player, start playing it, write down when user started playing a sound so he's under cooldown
                            var player = new NSoundPlayer(programSettings.OutputDevice, soundlist[i].GetFile(rng), programSettings.Volume);
                            var lenght = player.GetTimeLenght();
                            SoundPlayererStack.Add(player);
                            userDB[user] = DateTime.Now + lenght;

                            return(true);
                        }
                        return(false);
                    }
                }
            }
            Debug.WriteLine("User " + user + " has to wait " + (DateTime.Now - (userDB[user] + TimeSpan.FromSeconds(delay))).TotalSeconds + " seconds.");
            return(false);
        }