Пример #1
0
 public static void Timer(object source, ElapsedEventArgs e)
 {
     using (var db = new LiteDatabase(@"Guardians.db"))
     {
         var Guardians = db.GetCollection <UserData>("Guardians");
         var Guardian  = Guardians.Find(x => x.GroupMeTime != null);
         foreach (var time in Guardian)
         {
             if (time.GroupMeTime != null)
             {
                 int count = GroupMe.CountGroup(time.GroupMeGroup, creds.GroupMe);
                 if (Convert.ToDateTime(time.GroupMeTime).AddMinutes(15) <= DateTime.Now || count > 2)
                 {
                     GroupMe.DeleteGroup(time.GroupMeGroup, creds.GroupMe);
                     time.GroupMeGroup = null;
                     time.GroupMeTime  = null;
                     time.Channels     = null;
                     time.GroupMeBot   = null;
                     Guardians.Update(time);
                 }
                 else if (count == 2)
                 {
                     GroupMe.CloseGroup(time.GroupMeGroup, creds.GroupMe);
                     time.GroupMeTime = null;
                     Guardians.Update(time);
                 }
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Read every message that gets sent
        /// </summary>
        public async void ReadmessagesAsync(SocketMessage message)
        {
            // Set up the Socket User Message so we can use it for context for later
            var  usermessage = message as SocketUserMessage;
            var  chnl        = message.Channel as SocketGuildChannel;
            bool GuildCheck  = true;

            // Make sure we don't do anything in RTX-London
            try
            {
                if (chnl.Guild.Id == 358283239053590528)
                {
                    GuildCheck = false;
                }
            }
            catch { }
            if (GuildCheck == true)
            {
                try
                {
                    if (Validation.Istext(message))
                    {
                        // Check if the message is a command based off if a bang is the first letter
                        if (Validation.Iscommand(message))
                        {
                            // Set up Command Context
                            var context = new CommandContext(discordclient, usermessage);
                            // Check if the message sent matches an actual command in the approved or public commands
                            bool found = false;
                            if (Validation.CheckCommand(message, "help") && found == false)
                            {
                                found = await Help.HelpCommands(message, context);
                            }
                            if (message.Channel.Name.ToLower() == "landing" && found == false)
                            {
                                found = await Landing.LandingCommands(message, context, discordclient);
                            }
                            else
                            {
                                // Head Guardian/Admin Commands
                                if (Validation.IsHGorAdmin(message, discordclient) && found == false)
                                {
                                    found = await Admins.AdminCommands(message, context, discordclient);
                                }
                                // Team Lead Commands
                                if (Validation.IsTL(message) && found == false)
                                {
                                    found = await TeamLead.TeamCommand(message, context);
                                }
                                if (found == false)
                                {
                                    found = await Fun.FunCommands(message, context, discordclient);
                                }
                                if (found == false)
                                {
                                    found = await Music.MusicCommands(message, context, discordclient, _lavaNode);
                                }
                                if (found == false)
                                {
                                    found = await Phone.PhoneCommands(message, discordclient);
                                }
                            }
                        }
                        // Check if there were any mentions
                        else if (Validation.BotMentioned(message, discordclient))
                        {
                            // Set up Command Context
                            var context = new CommandContext(discordclient, usermessage);
                            if (message.Content.Replace("<@!503445217530085396>", "").Trim() == "")
                            {
                                // If so send a gif
                                await context.Channel.SendMessageAsync(Angela.RandomAngela());
                            }
                        }
                        // Log all text
                        WriteLog(message.Channel + ": " + message.Author + " - " + message.Content);
                        if (!reg.IsMatch(message.Content) && message.Author.IsBot == false)
                        {
                            try
                            {
                                using (var db = new LiteDatabase(@"Guardians.db"))
                                {
                                    var Guardians = db.GetCollection <UserData>("Guardians");
                                    var Guardian  = Guardians.Find(x => x.GroupMeGroup != null && x.Channels.Contains(message.Channel.Name.ToLower()) && x.GroupMeTime == null);
                                    foreach (var notify in Guardian)
                                    {
                                        if (notify.DiscordUsername.ToLower() != message.Author.Username.ToLower() + "#" + message.Author.Discriminator.ToString())
                                        {
                                            GroupMe.SendMessage(notify.GroupMeBot, message.Channel.Name, message.Author.Username, message.Content, creds.GroupMe);
                                        }
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
                catch { Console.WriteLine("Parsing Commands timed out: " + message.Channel.Name + " " + message.Content); }
            }
        }