コード例 #1
0
        public async Task <List <EventMessageObject> > GetMessage(IDiscordGuild guild, EventMessageType type, IDiscordUser user)
        {
            var channels = await guild.GetChannelsAsync();

            var channelIds = channels.Select(x => x.Id.ToDbLong());

            IDiscordGuildUser owner = await guild.GetOwnerAsync();

            var ownerMention = owner.Mention;
            var ownerName    = owner.Username;

            List <EventMessageObject> output = new List <EventMessageObject>();

            using (var context = new MikiContext())
            {
                var messageObjects = await context.EventMessages
                                     .Where(x => channelIds.Contains(x.ChannelId) && (short)type == x.EventType)
                                     .ToListAsync();

                var allUsers = await guild.GetMembersAsync();

                foreach (var c in messageObjects)
                {
                    if (c == null)
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(c.Message))
                    {
                        continue;
                    }

                    string modifiedMessage = c.Message;

                    modifiedMessage = modifiedMessage.Replace("-um", user.Mention);
                    modifiedMessage = modifiedMessage.Replace("-uc", guild.MemberCount.ToString());
                    modifiedMessage = modifiedMessage.Replace("-u", user.Username);

                    modifiedMessage = modifiedMessage.Replace("-ru", allUsers.ElementAt(MikiRandom.Next(0, allUsers.Count())).Username);

                    modifiedMessage = modifiedMessage.Replace("-now", DateTime.Now.ToShortDateString());
                    modifiedMessage = modifiedMessage.Replace("-s", guild.Name);

                    modifiedMessage = modifiedMessage.Replace("-om", ownerMention);
                    modifiedMessage = modifiedMessage.Replace("-o", ownerName);

                    modifiedMessage = modifiedMessage.Replace("-cc", channels.Count.ToString());
                    modifiedMessage = modifiedMessage.Replace("-vc", channels.Count.ToString());

                    output.Add(new EventMessageObject()
                    {
                        message            = modifiedMessage,
                        destinationChannel = channels.FirstOrDefault(x => x.Id.ToDbLong() == c.ChannelId)
                    });
                }
                return(output);
            }
        }
コード例 #2
0
		public static async Task UpdateGuildAsync(IDiscordGuild guild, DatabaseSettingId settingId, int newSetting)
		{
			var channels = await guild.GetChannelsAsync();
			foreach (var channel in channels)
			{
				await UpdateAsync((long)channel.Id, settingId, newSetting);
			}
		}
コード例 #3
0
        public async Task SetEnabledAll(IDiscordGuild guildId, bool enabled)
        {
            var channels = await guildId.GetChannelsAsync();

            foreach (IDiscordChannel c in channels)
            {
                await SetEnabled(c.Id, enabled);
            }
        }
コード例 #4
0
        public async Task <List <EventMessageObject> > GetMessageAsync(
            DbContext db, IDiscordGuild guild, EventMessageType type, IDiscordUser user)
        {
            var channels   = (await guild.GetChannelsAsync()).ToList();
            var channelIds = channels.Select(x => (long)x.Id);

            IDiscordGuildUser owner = await guild.GetOwnerAsync();

            var ownerMention = owner.Mention;
            var ownerName    = owner.Username;

            List <EventMessageObject> output = new List <EventMessageObject>();
            short t = (short)type;

            var messageObjects = await db.Set <EventMessage>()
                                 .Where(x => channelIds.Contains(x.ChannelId) && t == x.EventType)
                                 .ToListAsync();

            foreach (var c in messageObjects)
            {
                if (c == null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(c.Message))
                {
                    continue;
                }

                string modifiedMessage = c.Message;

                modifiedMessage = modifiedMessage.Replace("-um", user.Mention);
                modifiedMessage = modifiedMessage.Replace("-uc", guild.MemberCount.ToString());
                modifiedMessage = modifiedMessage.Replace("-u", user.Username);

                modifiedMessage = modifiedMessage.Replace("-now", DateTime.Now.ToShortDateString());
                modifiedMessage = modifiedMessage.Replace("-s", guild.Name);

                modifiedMessage = modifiedMessage.Replace("-om", ownerMention);
                modifiedMessage = modifiedMessage.Replace("-o", ownerName);

                modifiedMessage = modifiedMessage.Replace("-cc", channels.Count().ToString());
                modifiedMessage = modifiedMessage.Replace("-vc", channels.Count().ToString());

                output.Add(new EventMessageObject
                {
                    Message            = modifiedMessage,
                    DestinationChannel = channels.FirstOrDefault(
                        x => (long)x.Id == c.ChannelId) as IDiscordTextChannel
                });
            }

            return(output);
        }
コード例 #5
0
ファイル: WelcomeMessages.cs プロジェクト: SnipeFrost/Miki
        public async Task <List <EventMessageObject> > GetMessage(IDiscordGuild guild, EventMessageType type, IDiscordUser user)
        {
            long guildId = guild.Id.ToDbLong();
            List <IDiscordMessageChannel> channels = await guild.GetChannelsAsync();

            List <EventMessageObject> output = new List <EventMessageObject>();

            using (var context = new MikiContext())
            {
                foreach (IDiscordMessageChannel c in channels)
                {
                    EventMessage messageObject = await context.EventMessages.FindAsync(c.Id.ToDbLong(), (short)type);

                    if (messageObject == null)
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(messageObject.Message))
                    {
                        continue;
                    }

                    string modifiedMessage       = messageObject.Message;
                    List <IDiscordUser> allUsers = await c.GetUsersAsync();

                    modifiedMessage = modifiedMessage.Replace("-um", user.Mention);
                    modifiedMessage = modifiedMessage.Replace("-uc", (await user.Guild.GetUserCountAsync()).ToString());
                    modifiedMessage = modifiedMessage.Replace("-u", string.IsNullOrEmpty(user.Nickname) ? user.Username : user.Nickname);

                    modifiedMessage = modifiedMessage.Replace("-ru", allUsers[MikiRandom.Next(0, allUsers.Count)].GetName());

                    modifiedMessage = modifiedMessage.Replace("-now", DateTime.Now.ToShortDateString());
                    modifiedMessage = modifiedMessage.Replace("-s", user.Guild.Name);

                    modifiedMessage = modifiedMessage.Replace("-om", (await user.Guild.GetOwnerAsync()).Mention);
                    modifiedMessage = modifiedMessage.Replace("-o", string.IsNullOrEmpty((await user.Guild.GetOwnerAsync()).Nickname) ? (await user.Guild.GetOwnerAsync()).Username : (await user.Guild.GetOwnerAsync()).Nickname);

                    modifiedMessage = modifiedMessage.Replace("-cc", (await user.Guild.GetChannelCountAsync()).ToString());
                    modifiedMessage = modifiedMessage.Replace("-vc", (await user.Guild.GetVoiceChannelCountAsync()).ToString());

                    EventMessageObject o = new EventMessageObject()
                    {
                        message            = modifiedMessage,
                        destinationChannel = c
                    };

                    output.Add(o);
                }
                return(output);
            }
        }
コード例 #6
0
 public static Task <IDiscordGuildChannel> FindChannelByNameAsync(IDiscordGuild guild, string id)
 => guild.GetChannelsAsync()
 .Map(y => y.FirstOrDefault(x => x.Name.ToLowerInvariant() == id));