示例#1
0
        public void Add(string name, T value)
        {
            StringUtils.CheckAndLowerStringId(ref name);

            if (NameToId.ContainsKey(name))
            {
                throw new ArgumentException($"'{name}' item already exists in this collection.");                 //Should this throw BotErrors too?
            }

            ulong id = BotUtils.GenerateUniqueId(IdToValue.ContainsKey);

            NameToId[name] = id;
            IdToValue[id]  = value;
        }
        public async Task TagGroupAddCommand(string groupName)
        {
            groupName = groupName.ToLowerInvariant();

            var user       = Context.user;
            var memory     = MemorySystem.memory;
            var globalData = memory.GetData <TagSystem, TagGlobalData>();
            var userData   = memory[user].GetData <TagSystem, TagUserData>();

            if (globalData.tagGroups.Any(g => g.Value.name == groupName))
            {
                throw new BotError($@"Group `{groupName}` already exists. Pick an unique name.");
            }

            ulong groupId = BotUtils.GenerateUniqueId(globalData.tagGroups.ContainsKey);

            //Create the group
            globalData.tagGroups[groupId] = new TagGroup(user.Id, groupName);

            //Subscribe the user to it
            userData.subscribedTagGroups.Add(groupId);
        }
        public async Task TagAddCommand(string tagName, [Remainder] string text)
        {
            tagName = tagName.ToLowerInvariant();

            var user       = Context.user;
            var server     = Context.server;
            var memory     = MemorySystem.memory;
            var globalData = memory.GetData <TagSystem, TagGlobalData>();
            var userData   = memory[user].GetData <TagSystem, TagUserData>();

            EnsureTagIsNotDefined(tagName);

            ulong tagId = BotUtils.GenerateUniqueId(globalData.tags.ContainsKey);

            //Create tag
            globalData.tags[tagId] = new Tag(user.Id, tagName, text);

            //Subscribe the user to it
            if (!userData.subscribedTags.Contains(tagId))
            {
                userData.subscribedTags.Add(tagId);
            }
        }