Beispiel #1
0
        public string SetDefaultCanteen(CanteenName defaultCanteen, MensaBotEntities mensaBotEntities, string channelId, string conversationId, string serviceURL)
        {
            DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);

            if (DatabaseUtilities.AddEntry(DatabaseUtilities.DefaultMensaTag, defaultCanteen.ToString(), mensaBotEntities, channelId, conversationId))
            {
                return(Lang.add_canteen);
            }
            else
            {
                return(Lang.add_canteen_failed);
            }
        }
Beispiel #2
0
        public string SetStyle(string style, MensaBotEntities mensaBotEntities, string channelId, string conversationId, string serviceURL)
        {
            FoodDisplayStyle foodDisplayStyle;

            if (FoodDisplayStyle.TryParse(style.ToUpper(), out foodDisplayStyle))
            {
                DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);
                if (DatabaseUtilities.AddEntry(DatabaseUtilities.StyleTag, foodDisplayStyle.ToString().ToLower(), mensaBotEntities, channelId, conversationId))
                {
                    return(Lang.style_update + ": " + foodDisplayStyle.ToString().ToLower());
                }
                else
                {
                    return(Lang.style_fail_to_add_database);
                }
            }
            else
            {
                return(Lang.style_not_found + ": " + style);
            }
        }
Beispiel #3
0
        public string SetDefaults(string activityMessage, MensaBotEntities mensaBotEntities, string channelId, string conversationId, string serviceURL)
        {
            if (activityMessage.StartsWith("set help"))
            {
                var message = MessageInterpreter.MarkBold(Lang.set_help) + MessageInterpreter.DrawLine
                              + Lang.set_help_canteen + MessageInterpreter.DrawLine
                              + Lang.set_help_filter + MessageInterpreter.DrawLine
                              + Lang.set_help_style + MessageInterpreter.DrawLine
                              + Lang.set_help_trigger + MessageInterpreter.DrawLine
                              + Lang.language_help;

                return(message);
            }

            string[] setMessageParts = activityMessage.Remove(0, 1).ToLower().Split(' ');

            if (setMessageParts.Length != 3)
            {
                return(Lang.set_fail);
            }

            bool containsCommand = MessageInterpreter.Get.ContainsCommands(MessageInterType.MAIN_COMMAND, setMessageParts[1]);

            if (containsCommand)
            {
                DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);
                CanteenName canteenName = MessageInterpreter.Get.FindCanteen(setMessageParts[2]);

                if (canteenName == CanteenName.none)
                {
                    return(Lang.canteen_not_found + " " + MessageInterpreter.MarkBold(setMessageParts[2]));
                }

                return(CommandBucket.Get.SetDefaultCanteen(canteenName, mensaBotEntities, channelId, conversationId, serviceURL));
            }

            if (setMessageParts[1] == "language")
            {
                DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);

                var lang = activityMessage.Split(' ');
                if (lang.Length != 3)
                {
                    return(Lang.language_help);
                }

                return(CommandBucket.Get.SetLanguage(mensaBotEntities, lang[2], channelId, conversationId));
            }

            if (setMessageParts[1] == "trigger")
            {
                DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);

                var time = activityMessage.Split(' ');
                if (time.Length != 3)
                {
                    return(Lang.fail_so_define_trigger);
                }

                return(CommandBucket.Get.SetTrigger(mensaBotEntities, time[2], channelId, conversationId));
            }


            if ((setMessageParts[1].ToLower() == "style"))
            {
                DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);
                return(CommandBucket.Get.SetStyle(setMessageParts[2], mensaBotEntities, channelId, conversationId, serviceURL));
            }

            if ((setMessageParts[1].ToLower() == "filter"))
            {
                DatabaseUtilities.CreateChatEntry(mensaBotEntities, channelId, conversationId, serviceURL);

                var tags           = CommandBucket.Get.SetIgnoreTags(setMessageParts[2], MessageInterpreter.ParamDivider);
                var tagsAdditional = CommandBucket.Get.SetIgnoreTags(setMessageParts[2], MessageInterpreter.ParamDivider);

                if (tags != null && tagsAdditional != null)
                {
                    tags.AddRange(tagsAdditional);
                }
                if (tags == null && tagsAdditional != null)
                {
                    tags = tagsAdditional;
                }

                if (tags == null)
                {
                    return(Lang.failed_sorry + MessageInterpreter.LineBreak + Lang.add_tags_failed);
                }

                tags = tags.Distinct().ToList();

                string enumToString  = "";
                string displayString = "";
                for (int i = 0; i < tags.Count - 1; i++)
                {
                    enumToString  += tags[i].ToString().ToLower() + MessageInterpreter.ParamDivider;
                    displayString += FoodElement.FoodTagsToString(tags[i]) + MessageInterpreter.ParamDivider;
                }
                enumToString  += tags[tags.Count - 1].ToString().ToLower();
                displayString += FoodElement.FoodTagsToString(tags[tags.Count - 1]);

                if (DatabaseUtilities.AddEntry(DatabaseUtilities.IgnoreTags, enumToString, mensaBotEntities, channelId, conversationId))
                {
                    return(Lang.add_tags + " " + MessageInterpreter.MarkBold(displayString));
                }
                else
                {
                    return(Lang.add_tags_failed + MessageInterpreter.LineBreak + Lang.add_tags_failed);
                }
            }

            return(CommandBucket.Get.CreateUnknownCommand());
        }