public Task SendMissedMessagesAsync(ICommandSender sender, SayPlace place, string target, int accountID, int maxCount = MessageResendCount) { return(Task.Run(async() => { await sendHistorySemaphore.WaitAsync(); try { using (var db = new ZkDataContext()) { var acc = db.Accounts.Find(accountID); foreach (var entry in db.LobbyChatHistories.Where(x => (x.Target == target) && (x.SayPlace == place) && (x.Time >= acc.LastLogout)) .OrderByDescending(x => x.Time) .Take(maxCount) .OrderBy(x => x.Time)) { await sender.SendCommand(entry.ToSay()); } } } catch (Exception ex) { Trace.TraceError("Error sending chat history: {0}", ex); } finally { sendHistorySemaphore.Release(); } })); }
public SayingEventArgs(SayPlace sayPlace, string channel, string text, bool isEmote) { SayPlace = sayPlace; Channel = channel; Text = text; IsEmote = isEmote; }
/// <summary> /// Say something through chat system /// </summary> /// <param name="place">Pick user (private message) channel or battle</param> /// <param name="channel">Channel or User name</param> /// <param name="text">chat text</param> /// <param name="isEmote">is message emote? (channel or battle only)</param> public void Say(SayPlace place, string channel, string text, bool isEmote) { if (String.IsNullOrEmpty(text)) { return; } switch (place) { case SayPlace.Channel: if (isEmote) { con.SendCommand(0, "SAYEX", channel, text); } else { con.SendCommand(0, "SAY", channel, text); } break; case SayPlace.User: con.SendCommand(0, "SAYPRIVATE", channel, text); break; case SayPlace.Battle: if (isEmote) { con.SendCommand(0, "SAYBATTLEEX", text); } else { con.SendCommand(0, "SAYBATTLE", text); } break; } }
public event EventHandler <TasSayEventArgs> Said = delegate { }; // this is fired when any kind of say message is recieved /// <summary> /// Say something through chat system /// </summary> /// <param Name="place">Pick user (private message) channel or battle</param> /// <param Name="channel">Channel or User Name</param> /// <param Name="inputtext">chat text</param> /// <param Name="isEmote">is message emote? (channel or battle only)</param> /// <param Name="linePrefix">text to be inserted in front of each line (example: "!pm xyz")</param> public async Task Say(SayPlace place, string channel, string inputtext, bool isEmote, bool isRing = false) { if (string.IsNullOrEmpty(inputtext)) { return; } var lines = inputtext.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var text in lines) { if (string.IsNullOrEmpty(text)) { continue; } var args = new SayingEventArgs(place, channel, text, isEmote); Saying(this, args); if (args.Cancel) { continue; } if ((args.SayPlace == SayPlace.Channel) && !JoinedChannels.ContainsKey(args.Channel)) { await JoinChannel(args.Channel); } var say = new Say() { Target = args.Channel, Place = args.SayPlace, Text = args.Text, IsEmote = args.IsEmote, Ring = isRing }; await SendCommand(say); } }
public TasSayEventArgs(SayPlace place, string channel, string username, string text, bool isEmote) { Place = place; UserName = username; Text = text; IsEmote = isEmote; Channel = channel; }
public async Task SendMissedMessages(ICommandSender sender, SayPlace place, string target, int accountID, int maxCount = OfflineMessageResendCount) { using (var db = new ZkDataContext()) { var acc = await db.Accounts.FindAsync(accountID); await db.LobbyChatHistories.Where(x => x.Target == target && x.SayPlace == place && x.Time >= acc.LastLogout) .OrderByDescending(x => x.Time) .Take(maxCount) .OrderBy(x => x.Time) .ForEachAsync(async (chatHistory) => { await sender.SendCommand(chatHistory.ToSay()); }); } }
public async Task SendMissedMessages(ICommandSender sender, SayPlace place, string target, int accountID, int maxCount = OfflineMessageResendCount) { using (var db = new ZkDataContext()) { var acc = await db.Accounts.FindAsync(accountID); await db.LobbyChatHistories.Where(x => x.Target == target && x.SayPlace == place && x.Time >= acc.LastLogout) .OrderByDescending(x => x.Time) .Take(maxCount) .OrderBy(x => x.Time) .ForEachAsync(async(chatHistory) => { await sender.SendCommand(chatHistory.ToSay()); }); } }
public async Task SendMissedMessages(ICommandSender sender, SayPlace place, string target, int accountID, int maxCount = OfflineMessageResendCount) { using (var db = new ZkDataContext()) { var acc = await db.Accounts.FindAsync(accountID); await db.LobbyChatHistories.Where(x => x.Target == target && x.SayPlace == place && x.Time >= acc.LastLogout) .OrderByDescending(x => x.Time) .Take(maxCount) .OrderBy(x => x.Time) .ForEachAsync(async (chatHistory) => { await sender.SendCommand(chatHistory.ToSay()); }); if (place == SayPlace.User) { // don't keep PMs longer than needed db.LobbyChatHistories.DeleteAllOnSubmit(db.LobbyChatHistories.Where(x => x.Target == target && x.SayPlace == SayPlace.User).ToList()); db.SaveChanges(); } } }
/// <summary> /// Say something through chat system /// </summary> /// <param name="place">Pick user (private message) channel or battle</param> /// <param name="channel">Channel or User name</param> /// <param name="inputtext">chat text</param> /// <param name="isEmote">is message emote? (channel or battle only)</param> public void Say(SayPlace place, string channel, string inputtext, bool isEmote) { if (String.IsNullOrEmpty(inputtext)) { return; } var lines = inputtext.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var text in lines) { if (String.IsNullOrEmpty(text)) { return; } switch (place) { case SayPlace.Channel: if (isEmote) { con.SendCommand(0, "SAYEX", channel, text); } else { con.SendCommand(0, "SAY", channel, text); } break; case SayPlace.User: con.SendCommand(0, "SAYPRIVATE", channel, text); break; case SayPlace.Battle: if (isEmote) { con.SendCommand(0, "SAYBATTLEEX", text); } else { con.SendCommand(0, "SAYBATTLE", text); } break; } } }
public Task SendMissedMessagesAsync(ICommandSender sender, SayPlace place, string target, int accountID, int maxCount = MessageResendCount) { return Task.Run(async () => { await sendHistorySemaphore.WaitAsync(); try { using (var db = new ZkDataContext()) { var acc = db.Accounts.Find(accountID); foreach (var entry in db.LobbyChatHistories.Where(x => (x.Target == target) && (x.SayPlace == place) && (x.Time >= acc.LastLogout)) .OrderByDescending(x => x.Time) .Take(maxCount) .OrderBy(x => x.Time)) await sender.SendCommand(entry.ToSay()); if (place == SayPlace.User) { // don't keep PMs longer than needed db.LobbyChatHistories.DeleteAllOnSubmit( db.LobbyChatHistories.Where(x => (x.Target == target) && (x.SayPlace == SayPlace.User)).ToList()); db.SaveChanges(); } } } catch (Exception ex) { Trace.TraceError("Error sending chat history: {0}", ex); } finally { sendHistorySemaphore.Release(); } }); }
/// <summary> /// Say something through chat system /// </summary> /// <param name="place">Pick user (private message) channel or battle</param> /// <param name="channel">Channel or User name</param> /// <param name="text">chat text</param> /// <param name="isEmote">is message emote? (channel or battle only)</param> public void Say(SayPlace place, string channel, string text, bool isEmote) { if (String.IsNullOrEmpty(text)) return; switch (place) { case SayPlace.Channel: if (isEmote) con.SendCommand(0, "SAYEX", channel, text); else con.SendCommand(0, "SAY", channel, text); break; case SayPlace.User: con.SendCommand(0, "SAYPRIVATE", channel, text); break; case SayPlace.Battle: if (isEmote) con.SendCommand(0, "SAYBATTLEEX", text); else con.SendCommand(0, "SAYBATTLE", text); break; } }
/// <summary> /// Say something through chat system /// </summary> /// <param Name="place">Pick user (private message) channel or battle</param> /// <param Name="channel">Channel or User Name</param> /// <param Name="inputtext">chat text</param> /// <param Name="isEmote">is message emote? (channel or battle only)</param> /// <param Name="linePrefix">text to be inserted in front of each line (example: "!pm xyz")</param> public async Task Say(SayPlace place, string channel, string inputtext, bool isEmote, string linePrefix = "") { if (String.IsNullOrEmpty(inputtext)) return; var lines = inputtext.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var text in lines) { if (String.IsNullOrEmpty(text)) continue; var sentText = linePrefix + text; var args = new SayingEventArgs(place, channel, sentText, isEmote); Saying(this, args); if (args.Cancel) continue; switch (place) { case SayPlace.Channel: if (!JoinedChannels.ContainsKey(args.Channel)) JoinChannel(args.Channel); if (args.IsEmote) await con.SendCommand("SAYEX", args.Channel, args.Text); else await con.SendCommand("SAY", args.Channel, args.Text); break; case SayPlace.User: await con.SendCommand("SAYPRIVATE", args.Channel, args.Text); break; case SayPlace.Battle: if (args.IsEmote) await con.SendCommand("SAYBATTLEEX", args.Text); else await con.SendCommand("SAYBATTLE", args.Text); break; case SayPlace.BattlePrivate: if (args.IsEmote) await con.SendCommand("SAYBATTLEPRIVATEEX", channel, args.Text); else await con.SendCommand("SAYBATTLEPRIVATE", channel, args.Text); break; } } }
/// <summary> /// Say something through chat system /// </summary> /// <param Name="place">Pick user (private message) channel or battle</param> /// <param Name="channel">Channel or User Name</param> /// <param Name="inputtext">chat text</param> /// <param Name="isEmote">is message emote? (channel or battle only)</param> /// <param Name="linePrefix">text to be inserted in front of each line (example: "!pm xyz")</param> public async Task Say(SayPlace place, string channel, string inputtext, bool isEmote, string linePrefix = "") { if (String.IsNullOrEmpty(inputtext)) { return; } var lines = inputtext.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var text in lines) { if (String.IsNullOrEmpty(text)) { continue; } var sentText = linePrefix + text; var args = new SayingEventArgs(place, channel, sentText, isEmote); Saying(this, args); if (args.Cancel) { continue; } switch (place) { case SayPlace.Channel: if (!JoinedChannels.ContainsKey(args.Channel)) { JoinChannel(args.Channel); } if (args.IsEmote) { await con.SendCommand("SAYEX", args.Channel, args.Text); } else { await con.SendCommand("SAY", args.Channel, args.Text); } break; case SayPlace.User: await con.SendCommand("SAYPRIVATE", args.Channel, args.Text); break; case SayPlace.Battle: if (args.IsEmote) { await con.SendCommand("SAYBATTLEEX", args.Text); } else { await con.SendCommand("SAYBATTLE", args.Text); } break; case SayPlace.BattlePrivate: if (args.IsEmote) { await con.SendCommand("SAYBATTLEPRIVATEEX", channel, args.Text); } else { await con.SendCommand("SAYBATTLEPRIVATE", channel, args.Text); } break; } } }
public CommandConfig(string name, int level, string helpText, int throttling, SayPlace[] listenTo) : this(name, level, helpText, throttling) { this.listenTo = listenTo; }
/// <summary> /// Say something through chat system /// </summary> /// <param name="place">Pick user (private message) channel or battle</param> /// <param name="channel">Channel or User name</param> /// <param name="inputtext">chat text</param> /// <param name="isEmote">is message emote? (channel or battle only)</param> public void Say(SayPlace place, string channel, string inputtext, bool isEmote) { if (String.IsNullOrEmpty(inputtext)) return; var lines = inputtext.Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries); foreach (var text in lines) { if (String.IsNullOrEmpty(text)) return; switch (place) { case SayPlace.Channel: if (isEmote) con.SendCommand(0, "SAYEX", channel, text); else con.SendCommand(0, "SAY", channel, text); break; case SayPlace.User: con.SendCommand(0, "SAYPRIVATE", channel, text); break; case SayPlace.Battle: if (isEmote) con.SendCommand(0, "SAYBATTLEEX", text); else con.SendCommand(0, "SAYBATTLE", text); break; } } }
public Task Ring(SayPlace place, string channel, string text = null) { return(Say(place, channel, text ?? "Ringing " + channel, false, true)); }