Пример #1
0
        public GeneralModule GetModule(string name)
        {
            GeneralModule module = null;

            m_mapModules.TryGetValue(name, out module);
            return(module);
        }
Пример #2
0
            public async Task WhoIs(ulong userId)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //check if the user, which has written the message, has admin rights or is server owner
                    if (AdminModule.IsAuthorized(GeneralModule.GetGuildUserFromGuild(Context.Message.Author as SocketUser, guildChannel.Guild)))
                    {
                        await Context.Message.Channel.SendMessageAsync($"{Context.Message.Author.Username}, you dont have the permissions to do this!");

                        return;
                    }
                    if (Program.MyGuild.Users.ToList().Find(u => u.Id == userId) == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("User couldn't be found.");

                        return;
                    }
                    //user has admin rights
                    await Context.Message.Channel.SendMessageAsync($"{userId} => {Program.MyGuild.Users.ToList().Find(u => u.Id == userId)}");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("This command only works on a guild.");
                }
            }
Пример #3
0
        public async Task InviteAsync()
        {
            var userMock = new Mock <IDiscordUser>();

            userMock.Setup(x => x.GetDMChannelAsync())
            .Returns(Task.FromResult <IDiscordTextChannel>(
                         new DiscordGuildTextChannel(new DiscordChannelPacket(), null)));

            var messageMock = new Mock <IDiscordMessage>();

            messageMock.SetupGet(x => x.Author)
            .Returns(userMock.Object);

            Mock.SetContext(
                FetchDataStage.ChannelArgumentKey,
                new DiscordGuildTextChannel(new DiscordChannelPacket(), null));
            Mock.SetContext(CorePipelineStage.MessageContextKey, messageMock.Object);

            var general = new GeneralModule();
            await general.InviteAsync(Mock);

            Assert.True(Worker.TryGetMessage(out var response));
            Assert.Equal("miki_module_general_invite_message", response.Arguments.Properties.Content);

            Assert.True(Worker.TryGetMessage(out response));
            Assert.StartsWith("miki_module_general_invite_dm", response.Arguments.Properties.Content);
        }
Пример #4
0
        public async Task PingAsync()
        {
            var messageMock = new Mock <IDiscordMessage>();

            messageMock.SetupGet(x => x.Timestamp)
            .Returns(DateTimeOffset.Now);

            Mock.SetContext(
                FetchDataStage.ChannelArgumentKey,
                new DiscordGuildTextChannel(new DiscordChannelPacket(), null));
            Mock.SetContext(CorePipelineStage.MessageContextKey, messageMock.Object);

            var general = new GeneralModule();
            await general.PingAsync(Mock);

            Assert.True(Worker.TryGetMessage(out var response));

            Assert.NotNull(response.Arguments.Properties.Embed);
            Assert.Equal("Ping", response.Arguments.Properties.Embed.Title);
            Assert.Equal("ping_placeholder", response.Arguments.Properties.Embed.Description);

            Assert.True(Worker.TryGetMessage(out response));

            Assert.NotNull(response.Arguments.Properties.Embed);
            Assert.Equal($"Pong - {Environment.MachineName}",
                         response.Arguments.Properties.Embed.Title);
        }
Пример #5
0
        public void CurrentUptime_ShouldReturnValidUptimeString()
        {
            TimeSpan span = new TimeSpan(2, 1, 5);

            string expect = $" {span.Hours} Hours {span.Minutes} Minute {span.Seconds} Seconds";

            string actual = GeneralModule.CurrentUptime(span);

            Assert.Equal(expect, actual);
        }
Пример #6
0
        public override bool OnMessage(UIMessage msg)
        {
            switch (msg.type)
            {
            case UIMsgType.RandomEventDialog_Update_Effect:
                int rewardID = (int)msg.content[0];
                var list     = GeneralModule.GetRewardItem(rewardID);
                return(SetUpReward(list));

            default:
                return(false);
            }
        }
Пример #7
0
        //============================================================================
        //消息机制
        //============================================================================

        public void SendMessage(string target, string msg, params object[] args)
        {
            GeneralModule module = GetModule(target);

            if (module != null)
            {
                module.HandleMessage(msg, args);
            }
            else
            {
                var           list = GetCacheMessageList(target);
                MessageObject obj  = new MessageObject();
                obj.msg  = msg;
                obj.args = args;
                list.Add(obj);
            }
        }
Пример #8
0
            public async Task RemoveRankRole(int index)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //check if user has admin priviliges
                    if (AdminModule.IsAuthorized(GeneralModule.GetGuildUserFromGuild(Context.Message.Author as SocketUser, guildChannel.Guild)))
                    {
                        await Context.Message.Channel.SendMessageAsync("You cant do this.");

                        return;
                    }
                    ulong                   guildId = guildChannel.Guild.Id;
                    SocketGuild             guild   = guildChannel.Guild;
                    Dictionary <int, ulong> guildRankRoleCollection = RoleManagerService.RankRoleCollection[guildId];
                    if (guildRankRoleCollection == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("There are no roles to remove.");

                        return;
                    }
                    //if (guild.Roles.ToList().Find(r => r.Id == roleId) == null)
                    //{
                    //    await Context.Message.Channel.SendMessageAsync("This role dont exist on this server.");
                    //    return;
                    //}
                    //if (guildRankRoleCollection.Values.ToList().Contains(roleId))
                    //{
                    //    await Context.Message.Channel.SendMessageAsync("You cant remove this role, because it was never added.");
                    //    return;
                    //}
                    if (!guildRankRoleCollection.ContainsKey(index))
                    {
                        await Context.Message.Channel.SendMessageAsync("The current index is not in your role collection.");

                        return;
                    }
                    guildRankRoleCollection.Remove(index);
                    RoleManagerService.SaveRankRoleCollection();
                    await Context.Message.Channel.SendMessageAsync("Role successfully removed.");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("This is a server command only.");
                }
            }
Пример #9
0
        public GeneralModule CreateModule(string name, object args = null)
        {
            Debug.Log("name = " + name + ", args = " + args);

            if (HasModule(name))
            {
                Debuger.LogError("The Module<{0}> Has Existed!");
                return(null);
            }

            GeneralModule module = null;

            for (int i = 0; i < m_listModuleActivators.Count; i++)
            {
                module = m_listModuleActivators[i].CreateInstance(name);
                if (module != null)
                {
                    break;
                }
            }


            if (module == null)
            {
                Debuger.LogError("模块实例化失败!");
                return(null);
            }

            m_mapModules.Add(name, module);
            module.Create(args);

            //处理缓存的消息
            if (m_mapCacheMessage.ContainsKey(name))
            {
                List <MessageObject> list = m_mapCacheMessage[name];
                for (int i = 0; i < list.Count; i++)
                {
                    MessageObject msgobj = list[i];
                    module.HandleMessage(msgobj.msg, msgobj.args);
                }
                m_mapCacheMessage.Remove(name);
            }

            return(module);
        }
Пример #10
0
 public GeneralViewModel(GeneralModule module) : base(module, "General")
 {
     GeneralModule = module;
 }
Пример #11
0
 public async Task CalculateUptime()
 {
     TimeSpan uptime = DateTime.Now - Program.StartTime;
     await Context.Message.Channel.SendMessageAsync($"My current uptime is {GeneralModule.CurrentUptime(uptime)}. I'm online since {Program.StartTime} .");
 }