public static void addGuild(SocketGuild G) { jGuild g = new jGuild() { Name = G.Name, Id = G.Id, Channels = new List <jChannel>() }; foreach (SocketTextChannel C in G.TextChannels) { if (C == null) { continue; } jChannel c = new jChannel() { Name = C.Name, Id = C.Id, Users = new List <jUser>() }; g.Channels.Add(c); } Globals.addGuild(g); }
public async static Task <List <DateTimeOffset> > collectMessages(ISocketMessageChannel channel) { jGuild g = await Globals.requestDataFindAsync(item => item.Channels.Count(C => C.Id == channel.Id) > 0); jChannel c = g.Channels.Find(item => item.Id == channel.Id); return(c.fullTimestamps()); }
public static void indexChannel(ISocketMessageChannel channel, jChannel outChannel) { Console.WriteLine("Starting " + channel.Name + " index"); if (outChannel == null) { outChannel = new jChannel(channel); } var messages = new List <IReadOnlyCollection <IMessage> >(); try { messages = channel.GetMessagesAsync(int.MaxValue).ToEnumerable().ToList(); } catch (Exception ex) { return; } Console.WriteLine("Got messages for " + channel.Name); int threadCount = 0; foreach (IReadOnlyCollection <IMessage> collection in messages) { foreach (IMessage m in collection) { if (!outChannel.Users.Exists(item => item.Id == m.Author.Id)) { jUser newU = new jUser() { Id = m.Author.Id, Name = m.Author.Username, Timestamps = new List <DateTimeOffset>() }; newU.Timestamps.Add(m.Timestamp); outChannel.Users.Add(newU); } else { outChannel.Users.Find(item => item.Id == m.Author.Id).Timestamps.Add(m.Timestamp); } } #region old_threaded //threadCount++; //Thread TTh = new Thread(async delegate () //{ // foreach (IMessage m in collection) // { // try // { // //if (m.Author.IsBot || m.Author.IsWebhook || m.Content == "" || m.Conten) // if (m == null || m.Author == null) { continue; } // if (outChannel.Users.Exists(item => item.Id == m.Author.Id)) // { // try // { // outChannel.Users.Find(item => item.Id == m.Author.Id).Timestamps.Add(m.Timestamp); // } // catch (Exception ex) // { // continue; // } // } // else // { // if (adding.Contains(m.Author.Id)) // { // while (adding.Contains(m.Author.Id)) // { // Thread.Sleep(5); // } // try // { // outChannel.Users.Find(item => item.Id == m.Author.Id).Timestamps.Add(m.Timestamp); // } // catch (Exception ex) // { // continue; // } // continue; // } // adding.Add(m.Author.Id); // jUser newU = new jUser() // { // Id = m.Author.Id, // Name = m.Author.Username, // Timestamps = new List<DateTimeOffset>() // }; // newU.Timestamps.Add(m.Timestamp); // outChannel.Users.Add(newU); // adding.RemoveAll(item => item == m.Author.Id); // } // } // catch (Exception ex) { // continue; // } // } //}); //TTh.Name = channel.Name + " | " + threadCount + " | " + channel.Id; //Globals.threads.Add(TTh); //Globals.waitForLessLoad(); //TTh.Start(); #endregion } Console.WriteLine("Finished " + channel.Name + " index"); }
public static void LogMessage(IMessage message) { if (message.Author.IsBot) { return; } if (message.Content == "" || message.Content == null) { return; } var Context = client.GetChannel(message.Channel.Id) as SocketGuildChannel; if (Globals.requestDataWhere(item => item.Id == Context.Guild.Id).Count() == 0) { //Globals.globalData.Add(new jGuild //{ // Name = Context.Guild.Name, // Id = Context.Guild.Id, // Channels = new List<jChannel>() //}); Globals.addGuild(Context.Guild); //Console.WriteLine("[" + DateTime.Now.ToLocalTime().ToShortTimeString() + "]: Guild created"); } jGuild currentGuild = Globals.requestDataWhere(item => item.Id == Context.Guild.Id).First(); if (currentGuild.Channels.Where(item => item.Id == message.Channel.Id).Count() == 0) { currentGuild.Channels.Add(new jChannel { Name = message.Channel.Name, Id = message.Channel.Id, Users = new List <jUser>() }); //Console.WriteLine("[" + DateTime.Now.ToLocalTime().ToShortTimeString() + "]: Channel created"); } jChannel currentChannel = currentGuild.Channels.Where(item => item.Id == message.Channel.Id).First(); if (currentChannel.Users.Where(item => item.Id == message.Author.Id).Count() == 0) { currentChannel.Users.Add(new jUser { Name = message.Author.Username, Id = message.Author.Id, Timestamps = new List <DateTimeOffset>() }); //Console.WriteLine("[" + DateTime.Now.ToLocalTime().ToShortTimeString() + "]: User created"); currentChannel.Users.Last().Timestamps.Add(message.Timestamp); //Console.WriteLine("[" + DateTime.Now.ToLocalTime().ToShortTimeString() + "]: Message Logged successfully"); return; } jUser currentUser = currentChannel.Users.Where(item => item.Id == message.Author.Id).First(); if (!currentUser.Timestamps.Contains(message.Timestamp)) { currentUser.Timestamps.Add(message.Timestamp); //Console.WriteLine("[" + DateTime.Now.ToLocalTime().ToShortTimeString() + "]: Message Logged successfully"); } else { //Console.WriteLine("[" + DateTime.Now.ToLocalTime().ToShortTimeString() + "]: Existing Message Already Logged"); } }