private async Task Client_MessageDeleted(Cacheable <IMessage, ulong> arg1, Cacheable <IMessageChannel, ulong> cached) { var when = DateTime.Now; var arg2 = await cached.GetOrDownloadAsync(); if (!(arg2 is ITextChannel txt)) { return; } var service = Program.Services.GetRequiredService <MsgService>(); var content = service.GetLatestContent(arg1.Id); var dbMsg = await service.GetMessageAsync(arg1.Id); if (dbMsg == null) { return; } var builder = new EmbedBuilder() .WithTitle("Message Deleted") .WithColor(Color.Red) .WithDescription(content?.Content ?? "[unknown last content]"); builder.AddField("Channel", $"{txt.Mention}", true); builder.AddField("Author", $"{dbMsg.Author.Id}\r\n<@{dbMsg.Author.Id}>", true); builder.AddField("Original Sent", Discord.SnowflakeUtils.FromSnowflake(arg1.Id).ToString("dd/MM/yy HH:mm:ss.fff"), true); var message = await SendLog(txt.Guild, "messages", builder, arg1.Id); if (isDirty) { OnSave(); } var data = new messageData() { deleted = dbMsg, guild = txt.Guild, builder = builder, log = message, when = when }; new Thread(threadCheckDeleter).Start(data); }
public void Listen(StreamReader ear) { try { while (ircHandle.netStream.CanRead) { //listening things goes here try { string data = ear.ReadLine (); //Console.WriteLine(data); if (!string.IsNullOrEmpty (data)) { string prefix; string command; string[] param = new string[]{}; ParsingUtilities.ParseIrcMessageWithRegex (data, out prefix, out command, out param); switch (command) { case "PING": ircHandle.sendSrvData ("PONG " + param [0], ircHandle.strmWrite); Console.WriteLine ("Received PING, sending PONG"); break; case "PRIVMSG": if (ircHandle.ircChannels.Contains(param[0])) { //this is to a channel, not to logbot. log it! messageData threadData = new messageData (); threadData.nick = prefix.Split ('!') [0]; threadData.channel = param [0]; threadData.user = prefix; threadData.message = param [1]; Console.WriteLine(string.Format("{0} [{1}]: {2}", threadData.nick, threadData.channel, threadData.message)); logger.logMessage(threadData); if (threadData.channel == "#lounge") { if (threadData.message.StartsWith("[KILL]")) { //assume snapshot: collect snapshotData snapshot = new snapshotData(); try { ParsingUtilities.ParseSnapshotMessageRegex(threadData.message, out snapshot); Console.WriteLine(string.Format ("{0} killed by {1} for {2} | {3}, {4}", snapshot.username, snapshot.chatop, snapshot.reason, snapshot.first_snapstamp, snapshot.second_snapstamp)); logger.logSnapshot(snapshot); } catch (Exception e) { Console.WriteLine (string.Format (">>SNAPSHOT FAILED<<: {0} | {1}", e.Source, e.Message)); } } } } break; } } else { //why is the string empty? have we dc'd --yes we have. why the f**k does tcpclient.connected not update?? Console.WriteLine ("String is null - resetting socket"); Disconnect (); } } catch (Exception e) { //read error. shit. REESET THE F*****G SOCKETTT Console.WriteLine ("Some sort of read error..SHIT"); Console.WriteLine (e.Message); Console.WriteLine (e.StackTrace); Disconnect (); } } //from here, ircConn has disconnected. Attempt to reconnect.. } catch (Exception e) { //the listen routine is broken somehow. either an empty line has been sent and not handled, or the server has lost connection. Console.WriteLine ("Connection interrupted!"); Console.WriteLine (e.Message); Console.WriteLine (e.StackTrace); Disconnect (); } }