Ejemplo n.º 1
0
 public void Run(IrcMessage theMessage)
 {
     if (String.Equals(theMessage.CommandLine, theMessage.ServerConnetion.IrcClient.Nickname, StringComparison.OrdinalIgnoreCase))
     {
         theMessage.Answer("Ich bin gerade hier und laut meinem Logik System solltest du auch sehen können was ich schreibe");
         return;
     }
     using (var context = new BotContext())
     {
         SeenEntry entry  = context.SeenEntries.FirstOrDefault(x => x.User == context.Nicknames.FirstOrDefault(n => n.Name == theMessage.CommandLine).User);
         string    output = "";
         if (entry != null)
         {
             if (entry.LastSeen.HasValue)
             {
                 output = "Den/Die habe ich hier zuletzt am " + entry.LastSeen.Value.ToString("dd.MM.yyyy ") + "um" + entry.LastSeen.Value.ToString(" HH:mm:ss ") + "Uhr gesehen.";
             }
             if (entry.LastMessaged.HasValue)
             {
                 output += " Am " + entry.LastMessaged.Value.ToString("dd.MM.yyyy ") + "um" + entry.LastMessaged.Value.ToString(" HH:mm:ss ") + "Uhr sagte er/sie zuletzt: \"" + entry.LastMessage + "\".";
             }
             else
             {
                 output += " Den habe ich hier noch nie etwas schreiben sehen.";
             }
         }
         theMessage.Answer(!String.IsNullOrEmpty(output) ? output.Trim() : "Scheinbar sind meine Datensätze unvollständig, tut mir leid");
     }
 }
        private void JoinHandler(object sender, JoinEventArgs e)
        {
            lock (seenData)
            {
                var result = seenData.SeenEntries.Where(s => s.Nick == e.Who).FirstOrDefault();

                if (result != null)
                {
                    result.LastSeenTime = DateTime.Now;
                    result.LastAction   = "(JOIN)";
                    result.OnStatus     = true;
                }
                else
                {
                    var seenEntry = new SeenEntry();
                    seenData.SeenEntries.InsertOnSubmit(seenEntry);

                    seenEntry.Nick         = e.Who;
                    seenEntry.LastSeenTime = DateTime.Now;
                    seenEntry.LastAction   = "(JOIN)";
                    seenEntry.LastMessage  = "<no message yet>";
                    seenEntry.TimesSeen    = 0;
                    seenEntry.OnStatus     = true;
                }
                SaveDb();
            }
        }
        private void NamesHandler(object sender, NamesEventArgs e)
        {
            lock (seenData)
            {
                foreach (string name in e.UserList)
                {
                    var result = seenData.SeenEntries.Where(s => s.Nick == name).FirstOrDefault();

                    if (result != null)
                    {
                        result.LastSeenTime = DateTime.Now;
                        result.LastAction   = "(ON)";
                        result.OnStatus     = true;
                    }
                    else
                    {
                        var seenEntry = new SeenEntry();
                        seenData.SeenEntries.InsertOnSubmit(seenEntry);

                        seenEntry.Nick         = name;
                        seenEntry.LastSeenTime = DateTime.Now;
                        seenEntry.LastAction   = "(ON)";
                        seenEntry.LastMessage  = "<no message yet>";
                        seenEntry.TimesSeen    = 0;
                        seenEntry.OnStatus     = true;
                    }
                }
                SaveDb();
            }
        }
Ejemplo n.º 4
0
 private void Server_OnJoin(object sender, JoinEventArgs e)
 {
     using (var context = new BotContext())
     {
         SeenEntry entry = GetSeenEntry(context, e.Who);
         entry.LastSeen = null;
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 private void Server_OnQuit(object sender, IrcEventArgs e)
 {
     using (var context = new BotContext())
     {
         SeenEntry entry = GetSeenEntry(context, e.Data.Nick);
         entry.LastSeen = DateTime.Now;
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        public void Run(IrcMessage theMessage)
        {
            string channel;

            if (theMessage.CommandArgs.Count < 2 | !Int32.TryParse(theMessage.CommandArgs.FirstOrDefault(), out int tage))
            {
                if (theMessage.IsPrivate)
                {
                    theMessage.Answer("Da du mir Privat schreibst, kann ich den Channel nicht erraten. Verwende: !bots <Tage> <Channel>");
                    return;
                }
                channel = theMessage.Source;
            }
            else if (theMessage.CommandArgs.Count == 2)
            {
                channel = theMessage.CommandArgs[1];
            }
            else
            {
                theMessage.AnswerHelp(this);
                return;
            }

            if (!theMessage.Data.Irc.JoinedChannels.Contains(channel))
            {
                theMessage.Answer("In diesem Channel befinde ich mich nicht und kann daher keine Auskunft geben.");
                return;
            }

            using (var context = new BotContext())
            {
                var UserImChannel = theMessage.Data.Irc.GetChannel(channel).Users.Values.Select(x =>
                {
                    User u          = context.GetUser(x.Nick);
                    SeenEntry entry = context.SeenEntries.FirstOrDefault(s => s.User.Id == u.Id);
                    return(new { Nickname = x.Nick, User = u, SeenEntry = entry });
                }).ToList();

                string wahrscheinlichInaktiv = UserImChannel.Where(x => x.User == null || x.SeenEntry == null).Select(x => x.Nickname).Join(", ");
                string bestimmtInaktiv       = UserImChannel.Where(x => x.SeenEntry != null && x.SeenEntry.LastMessaged < DateTime.Now.AddDays(-tage)).Select(x => x.Nickname).Join(", ");

                if (!String.IsNullOrWhiteSpace(wahrscheinlichInaktiv))
                {
                    theMessage.Answer($"User die wahrscheinlich inaktiv sind: {wahrscheinlichInaktiv}");
                }

                if (!String.IsNullOrWhiteSpace(bestimmtInaktiv))
                {
                    theMessage.Answer($"User die definitiv länger als {tage} Tage inaktiv sind: {bestimmtInaktiv}");
                }

                if (String.IsNullOrWhiteSpace(wahrscheinlichInaktiv) && String.IsNullOrWhiteSpace(bestimmtInaktiv))
                {
                    theMessage.Answer("Keinen Benutzer gefunden der in diese Kriterien fällt");
                }
            }
        }
        private void NickChangeHandler(object sender, NickChangeEventArgs e)
        {
            lock (seenData)
            {
                var seenResult = seenData.SeenEntries.Where(s => s.Nick == e.OldNickname).FirstOrDefault();

                if (seenResult != null)
                {
                    seenResult.LastSeenTime = DateTime.Now;
                    seenResult.LastAction   = "(NICK) Nick changed to: " + e.NewNickname;
                    seenResult.OnStatus     = false;
                }

                seenResult = seenData.SeenEntries.Where(s => s.Nick == e.NewNickname).FirstOrDefault();
                if (seenResult != null)
                {
                    seenResult.LastSeenTime = DateTime.Now;
                    seenResult.LastAction   = "(NICK) Nick changed from: " + e.OldNickname;
                    seenResult.OnStatus     = true;
                }
                else
                {
                    var seenEntry = new SeenEntry();
                    seenData.SeenEntries.InsertOnSubmit(seenEntry);

                    seenEntry.Nick         = e.NewNickname;
                    seenEntry.LastSeenTime = DateTime.Now;
                    seenEntry.LastAction   = "(NICK) Nick changed from: " + e.OldNickname;
                    seenEntry.LastMessage  = "<no message yet>";
                    seenEntry.TimesSeen    = 0;
                    seenEntry.OnStatus     = true;
                }

                var aliasResult = seenData.AliasEntries.Where(a => a.Nick == e.OldNickname && a.Alias == e.NewNickname).FirstOrDefault();

                if (aliasResult == null)
                {
                    var aliasEntry = new AliasEntry();
                    seenData.AliasEntries.InsertOnSubmit(aliasEntry);

                    aliasEntry.Nick  = e.OldNickname;
                    aliasEntry.Alias = e.NewNickname;
                }

                aliasResult = seenData.AliasEntries.Where(a => a.Nick == e.NewNickname && a.Alias == e.OldNickname).FirstOrDefault();
                if (aliasResult == null)
                {
                    var aliasEntry = new AliasEntry();
                    seenData.AliasEntries.InsertOnSubmit(aliasEntry);

                    aliasEntry.Nick  = e.NewNickname;
                    aliasEntry.Alias = e.OldNickname;
                }

                SaveDb();
            }
        }
Ejemplo n.º 8
0
        private SeenEntry GetSeenEntry(BotContext context, string nick)
        {
            User      u     = context.GetUser(nick);
            SeenEntry entry = context.SeenEntries.FirstOrDefault(x => x.User.Id == u.Id);

            if (entry == null)
            {
                entry = new SeenEntry {
                    User = u
                };
                context.SeenEntries.Add(entry);
            }
            return(entry);
        }
Ejemplo n.º 9
0
 private void Server_OnPreProcessingMessage(object sender, IrcMessage theMessage)
 {
     if (theMessage.IsIgnored)
     {
         return;
     }
     using (var context = new BotContext())
     {
         SeenEntry entry = GetSeenEntry(context, theMessage.Nickname);
         entry.LastMessaged = DateTime.Now;
         entry.LastMessage  = theMessage.Message;
         context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
        private void NickChangeHandler(object sender, NickChangeEventArgs e)
        {
            lock (seenData)
            {
                var seenResult = seenData.SeenEntries.Where(s => s.Nick == e.OldNickname).FirstOrDefault();

                if (seenResult != null)
                {
                    seenResult.LastSeenTime = DateTime.Now;
                    seenResult.LastAction = "(NICK) Nick changed to: " + e.NewNickname;
                    seenResult.OnStatus = false;
                }

                seenResult = seenData.SeenEntries.Where(s => s.Nick == e.NewNickname).FirstOrDefault();
                if (seenResult != null)
                {
                    seenResult.LastSeenTime = DateTime.Now;
                    seenResult.LastAction = "(NICK) Nick changed from: " + e.OldNickname;
                    seenResult.OnStatus = true;
                }
                else
                {
                    var seenEntry = new SeenEntry();
                    seenData.SeenEntries.InsertOnSubmit(seenEntry);

                    seenEntry.Nick = e.NewNickname;
                    seenEntry.LastSeenTime = DateTime.Now;
                    seenEntry.LastAction = "(NICK) Nick changed from: " + e.OldNickname;
                    seenEntry.LastMessage = "<no message yet>";
                    seenEntry.TimesSeen = 0;
                    seenEntry.OnStatus = true;

                }

                var aliasResult = seenData.AliasEntries.Where(a => a.Nick == e.OldNickname && a.Alias == e.NewNickname).FirstOrDefault();

                if (aliasResult == null)
                {
                    var aliasEntry = new AliasEntry();
                    seenData.AliasEntries.InsertOnSubmit(aliasEntry);

                    aliasEntry.Nick = e.OldNickname;
                    aliasEntry.Alias = e.NewNickname;
                }

                aliasResult = seenData.AliasEntries.Where(a => a.Nick == e.NewNickname && a.Alias == e.OldNickname).FirstOrDefault();
                if (aliasResult == null)
                {
                    var aliasEntry = new AliasEntry();
                    seenData.AliasEntries.InsertOnSubmit(aliasEntry);

                    aliasEntry.Nick = e.NewNickname;
                    aliasEntry.Alias = e.OldNickname;
                }

                SaveDb();
            }
        }
Ejemplo n.º 11
0
        private void NamesHandler(object sender, NamesEventArgs e)
        {
            lock (seenData)
            {
                foreach (string name in e.UserList)
                {
                    var result = seenData.SeenEntries.Where(s => s.Nick == name).FirstOrDefault();

                    if (result != null)
                    {
                        result.LastSeenTime = DateTime.Now;
                        result.LastAction = "(ON)";
                        result.OnStatus = true;
                    }
                    else
                    {
                        var seenEntry = new SeenEntry();
                        seenData.SeenEntries.InsertOnSubmit(seenEntry);

                        seenEntry.Nick = name;
                        seenEntry.LastSeenTime = DateTime.Now;
                        seenEntry.LastAction = "(ON)";
                        seenEntry.LastMessage = "<no message yet>";
                        seenEntry.TimesSeen = 0;
                        seenEntry.OnStatus = true;
                    }
                }
                SaveDb();
            }
        }
Ejemplo n.º 12
0
        private void JoinHandler(object sender, JoinEventArgs e)
        {
            lock (seenData)
            {

                var result = seenData.SeenEntries.Where(s => s.Nick == e.Who).FirstOrDefault();

                if (result != null)
                {
                    result.LastSeenTime = DateTime.Now;
                    result.LastAction = "(JOIN)";
                    result.OnStatus = true;
                }
                else
                {
                    var seenEntry = new SeenEntry();
                    seenData.SeenEntries.InsertOnSubmit(seenEntry);

                    seenEntry.Nick = e.Who;
                    seenEntry.LastSeenTime = DateTime.Now;
                    seenEntry.LastAction = "(JOIN)";
                    seenEntry.LastMessage = "<no message yet>";
                    seenEntry.TimesSeen = 0;
                    seenEntry.OnStatus = true;
                }
                SaveDb();
            }
        }