Beispiel #1
0
        public async Task SetEnabledAll(IDiscordGuild guildId, bool enabled)
        {
            List <IDiscordMessageChannel> channels = await guildId.GetChannels();

            foreach (IDiscordMessageChannel c in channels)
            {
                await SetEnabled(c.Id, enabled);
            }
        }
Beispiel #2
0
        public async Task <List <EventMessageObject> > GetMessage(IDiscordGuild guild, EventMessageType type, IDiscordUser user)
        {
            long guildId = guild.Id.ToDbLong();
            List <IDiscordMessageChannel> channels = await guild.GetChannels();

            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);
            }
        }
        public async Task <List <Tuple <string, IDiscordMessageChannel> > > GetMessage(IDiscordGuild guild, EventMessageType type, IDiscordUser user)
        {
            long guildId = guild.Id.ToDbLong();
            List <IDiscordMessageChannel> channels = await guild.GetChannels();

            List <Tuple <string, IDiscordMessageChannel> > output = new List <Tuple <string, IDiscordMessageChannel> >();

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

                    if (messageObject == null)
                    {
                        continue;
                    }

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

                    string modifiedMessage = messageObject.Message;

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

                    modifiedMessage = modifiedMessage.Replace("-sc", user.Guild.UserCount.ToString());
                    modifiedMessage = modifiedMessage.Replace("-s", user.Guild.Name);

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

                    output.Add(new Tuple <string, IDiscordMessageChannel>(modifiedMessage, c));
                }
                return(output);
            }
        }