Esempio n. 1
0
 private void stringSaveMessage(ChatSharp.Events.PrivateMessageEventArgs e)
 {
     try
     {
         using (var DB = new internetEntities())
         {
             irkki testRow = new irkki
             {
                 viesti = e.PrivateMessage.Message,
                 nick   = e.PrivateMessage.User.Nick,
                 kanava = e.PrivateMessage.Source,
                 aika   = DateTime.Now,
                 maara  = 1
             };
             DB.irkki.Add(testRow);
             DB.SaveChanges();
         }
     }
     catch (Exception eip)
     {
         try {
             using (var DB = new internetEntities())
             {
                 DB.logs.Add(new logs {
                     message = e.ToString(), severity = 1
                 });
                 DB.SaveChanges();
             }
         } catch (Exception se)
         {
         }
     }
 }
Esempio n. 2
0
 private void storeRandMessageToBuffer(irkki message = null, irkki_old mesOld = null, string initiator = "")
 {
     try
     {
         using (var db = new DB.internetEntities())
         {
             rand_messages rm = null;
             if (message != null)
             {
                 rm = new rand_messages {
                     rowid_irc = message.id, message = message.viesti, kanava = message.kanava, initiator = initiator
                 };
             }
             else if (mesOld != null)
             {
                 rm = new rand_messages {
                     rowid_irc = mesOld.id, message = mesOld.viesti, kanava = mesOld.kanava, initiator = initiator
                 };
             }
             if (rm != null)
             {
                 db.rand_messages.Add(rm);
                 db.SaveChanges();
             }
         }
     } catch (Exception e)
     {
         helperClass.writeLog("storeRandMessageToBuffer() Message: " + e.ToString(), 3);
     }
 }
Esempio n. 3
0
 private irkki getRand(string channel, string like, string messageTarget = "")
 {
     try {
         using (var DB = new internetEntities())
         {
             List <string> sent_rands = DB.rand_messages.Where(x => (messageTarget == "" || x.initiator == messageTarget) && x.kanava == channel).Select(x => x.message).ToList();
             List <irkki>  tList      = null;
             tList = DB.irkki.Where(x => x.viesti != "x" && !x.viesti.StartsWith("!random") && (like == "" || x.viesti.Contains(like)) && x.kanava.ToLower() == channel.ToLower() && (!sent_rands.Contains(x.viesti))).OrderBy(x => Guid.NewGuid()).Take(1).ToList();
             irkki mes = null;
             if (tList.Any())
             {
                 mes = tList.First();
                 storeRandMessageToBuffer(mes, null, messageTarget);
                 return(mes);
             }
             else
             {
                 return(null);
             }
         }
     } catch (Exception e)
     {
         return(null);
     }
 }
Esempio n. 4
0
        private string random(string channel, string like = "", bool onlyOld = false, string messageTarget = "")
        {
            string    rand   = "";
            irkki     mes    = null;
            irkki_old oldMes = null;

            try
            {
                using (var DB = new internetEntities())
                {
                    double countOld = DB.irkki_old.Count();
                    double countNew = DB.irkki.Where(x => x.viesti != "x").Count();
                    double total    = countOld + countNew;
                    double limit    = rnd1.NextDouble();
                    if (onlyOld || (limit < countOld / total))  //Old
                    {
                        oldMes = getOldRand(channel, like, messageTarget);
                        if (oldMes != null)
                        {
                            rand = formRandomMessage(oldMes.aika.Value, oldMes.nick, oldMes.viesti);
                        }
                        else
                        {
                            mes = getRand(channel, like, messageTarget);
                            if (mes != null)
                            {
                                rand = formRandomMessage(mes.aika.Value, mes.nick, mes.viesti);
                            }
                        }
                    }
                    else   // new
                    {
                        mes = getRand(channel, like, messageTarget);
                        if (mes != null)
                        {
                            rand = formRandomMessage(mes.aika.Value, mes.nick, mes.viesti);
                        }
                        else
                        {
                            oldMes = getOldRand(channel, like, messageTarget);
                            if (oldMes != null)
                            {
                                rand = formRandomMessage(oldMes.aika.Value, oldMes.nick, oldMes.viesti);
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                helperClass.writeLog("Virhe random()-metodissa. Virheviesti: " + e.ToString(), 4);
            }
            return(rand);
        }
Esempio n. 5
0
 private void logMessage(IrcEventArgs e)
 {
     try
     {
         using (var DB = new internetEntities())
         {
             irkki testRow = new irkki
             {
                 viesti = e.Data.Message,
                 nick   = e.Data.Nick,
                 kanava = e.Data.Channel,
                 aika   = DateTime.Now,
                 maara  = 1
             };
             DB.irkki.Add(testRow);
             DB.SaveChanges();
         }
     }
     catch (Exception eip)
     { }
 }