private async Task DBStringsFirstSetup(BotChannel bChan) { await Task.Run(() => { foreach (string line in _success) { dbStrings.SaveNewLine(bChan, "SUCCESS", line); } foreach (string line in _fail) { dbStrings.SaveNewLine(bChan, "FAIL", line); } foreach (string line in _incident) { dbStrings.SaveNewLine(bChan, "INCIDENT", line); } foreach (string line in _tardy) { dbStrings.SaveNewLine(bChan, "TARDY", line); } foreach (string line in _shakeF) { dbStrings.SaveNewLine(bChan, "SHAKEF", line); } foreach (string line in _shakeS) { dbStrings.SaveNewLine(bChan, "SHAKES", line); } foreach (string line in _greets) { dbStrings.SaveNewLine(bChan, "GREET", line); } }); }
private async void OnTwitchChannelJoined(string channel, string botname) { if (channel == botname) { return; } // Make sure we have all couch database tables for any twitch channel we join BotChannel bChan = null; while (bChan == null) { bChan = await Program.Channels.GetTwitchChannelByName(channel); } if (bChan == null) { return; } if (!await dbStrings.TableInit(bChan)) { await DBStringsFirstSetup(bChan); } if (!StatsTableExists(bChan)) { StatsTableCreate(bChan, PLUGINSTATS); } await Core.Configs.ConfigSetup <CouchSettings>(bChan, PLUGINNAME, new CouchSettings()); }
private async void ReminderText(string twitchChannelName) { BotChannel bChan = await Program.Channels.GetTwitchChannelByName(twitchChannelName); CouchSettings settings = await Settings <CouchSettings>(bChan, PLUGINNAME); if (settings._active == false) { RemoveTimedMessage(bChan.TwitchChannelName); return; } if (!settings._couches[bChan.Key].couchOpen) { RemoveTimedMessage(bChan.TwitchChannelName); return; } if (settings._couches[bChan.Key].Count >= settings.couchsize) { Program.TwitchSayMessage(bChan.TwitchChannelName, $"Couch is now full."); RemoveTimedMessage(bChan.TwitchChannelName); return; } if (Core.CurrentTime > settings._couches[bChan.Key].lastActivationTime + settings.openTime) { RemoveTimedMessage(bChan.TwitchChannelName); return; } Program.TwitchSayMessage(bChan.TwitchChannelName, $"Couch is still open. Take a {Program.CommandCharacter}seat."); }
/// <summary> /// Stop server and release resources. /// </summary> public void Dispose() { // - Dispose all modules CocoritaModule.Dispose(); AudioModule.Dispose(); BotChannel.Dispose(); }
public JsonResponse onNewChannel(Dictionary <string, object> parameters) { JsonError error = null; if (Node.channels.hasChannel((string)parameters["channel"])) { return(new JsonResponse { result = null, error = new JsonError() { code = (int)RPCErrorCode.RPC_INVALID_PARAMETER, message = "Channel already exists." } }); } BotChannel channel = new BotChannel(Node.channels.getNextIndex(), (string)parameters["channel"]); Node.channels.setChannel((string)parameters["channel"], channel); if ((string)parameters["default"] == "1") { Node.settings.setOption("defaultChannel", channel.index.ToString()); } Node.settings.saveSettings(); Messages.addChannel(channel); return(new JsonResponse { result = "", error = error }); }
internal void RaiseOnDiscordGuildMemberUpdated(BotChannel bChan, UserEntry currentUser, UserEntry oldUser) { if (bChan != null && currentUser != null && oldUser != null) { OnDiscordMemberUpdated?.Invoke(bChan, currentUser, oldUser); } }
/// <summary> /// Gets a random string from DB table TableName(bChan.Key) under topic that are INUSE. /// </summary> /// <param name="bChan"></param> /// <param name="topic"></param> /// <returns></returns> public string GetRandomLine(BotChannel bChan, string topic) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.CommandType = CommandType.Text; cmd.Connection = Core.Data; cmd.CommandText = $"SELECT * FROM \"{TableName(bChan.Key)}\" WHERE inuse IS @inuse AND topic IS @topic ORDER BY RANDOM() LIMIT 1"; cmd.Parameters.AddWithValue("@inuse", true); cmd.Parameters.AddWithValue("@topic", topic); SQLiteDataReader result; try { result = cmd.ExecuteReader(); } catch (Exception) { Core.LOG(new LogEntry(LOGSEVERITY.ERROR, PLUGINNAME + "DatabseStrings", $"Database query failed hard. ({cmd.CommandText})")); throw; } result.Read(); if (!result.HasRows) { return("No string found in DB. Make sure to add lines and that they are inuse."); } return(result.GetString(3)); } }
private async void TwitchOnMessageCleared(object sender, OnMessageClearedArgs e) { BotChannel bChan = await Program.Channels.GetTwitchChannelByName(e.Channel); if(bChan != null) { Program.BotEvents.RaiseonTwitchMessageCleared(bChan, e); } }
/// <inheritdoc /> public async Task OnTurn(ITurnContext context) { try { BotChannel channel = await Task.Run(() => this.ConfigureChannel(context)); switch (context.Activity.Type) { case ActivityTypes.Message: await this.HandleMessage(context); break; case ActivityTypes.ConversationUpdate: await HandleConversationUpdate(context, channel); break; default: this.logger.LogInformation($"Encountered an unknown activity type of {context.Activity.Type}"); break; } } catch (Exception e) { throw new Exception($"Error while handling conversation response: {e.Message}", e); } }
public static async Task <bool> RoleRemoveUser(BotChannel bChan, UserEntry user, string role) { SocketGuild sGuild = Program.DiscordClient.GetGuild(bChan.GuildID); if (sGuild == null) { return(false); } SocketRole sRole = sGuild.Roles.FirstOrDefault(x => x.Name == role); if (sRole == null) { return(false); } IGuildUser iUser = await(sGuild as IGuild).GetUserAsync(user._discordUID); if (iUser == null) { return(false); } await iUser.RemoveRoleAsync(sRole as IRole); return(true); }
private async void OnDiscordReactionRemoved(BotChannel bChan, UserEntry user, DiscordReactionArgument args) { // Ignore self reaction string botName = Cipher.Decrypt(Program.BotName); if (user._discordUsername != botName) { RolesSettings settings = await Settings <RolesSettings>(bChan, PLUGINNAME); if (!settings._active) { return; } if (!settings.RoleTable.ContainsValue(args.Emote)) { return; } string role = settings.RoleTable.FirstOrDefault(x => x.Value == args.Emote).Key; if (settings.MarkedMessages.Exists(p => p.MessageID == args.MessageID)) { if (await MisfitBot_MKII.DiscordWrap.DiscordClient.RoleRemoveUser(bChan, user, role) == false) { await Core.LOG(new LogEntry(LOGSEVERITY.INFO, "RolesPlugin", $"OnDiscordReactionRemoved Failed to remove user({user._discordUsername}) from role({role})")); } } } }
private async void OnTwitchRaid(BotChannel bChan, RaidEventArguments e) { if (bChan.discordAdminChannel > 0) { await SayOnDiscordAdmin(bChan, $"RAID!! {e.SourceChannel} coming in with {e.RaiderCount} raiders."); } }
private async Task ListLinesFromDB(BotChannel bChan, ulong channelID, int page) { // LINES IN USE string inuseText = $"Currently stored lines...```fix{Environment.NewLine}" + $"These are lines stored in the database that the Insult plugin will use if they are marked as inuse.{Environment.NewLine}{Environment.NewLine}" + $"<ID> <INUSE> <TEXT> Page {page + 1}{Environment.NewLine}"; List <DBString> lines = dbStrings.GetRowsByTen(bChan, page); if (lines.Count == 0) { inuseText += "No hits. Try a lower page number."; } else { foreach (DBString entry in lines) { inuseText += String.Format("{0,4}", entry._id); //inuseText += String.Format("{0,8}", entry._topic); inuseText += String.Format("{0,7}", entry._inuse); inuseText += " " + entry._text + Environment.NewLine; } } inuseText += $"```Use command {CMC}insults list <page> to list a page. Those marked with **true** for INUSE are in rotation."; await SayOnDiscord(inuseText, channelID); }
private async void OnTwitchNewSub(BotChannel bChan, TwitchNewSubArguments e) { if (bChan.discordAdminChannel > 0) { await SayOnDiscordAdmin(bChan, $"{e.userDisplayname} subscribed for the first time."); } }
private async void OnTwitchNewFollower(BotChannel bChan, UserEntry user) { if (bChan.discordAdminChannel > 0) { await SayOnDiscordAdmin(bChan, $"Hey we got a new Twitch follower! {user._twitchDisplayname}"); } }
private async void OnTwitchSubGift(BotChannel bChan, TwitchSubGiftEventArguments e) { if (bChan.discordAdminChannel > 0) { await SayOnDiscordAdmin(bChan, $"{e.userDisplayname} gave {e.recipientDisplayname} a {e.subscriptionplanName}."); } }
private async void OnTwitchResub(BotChannel bChan, TwitchReSubArguments args) { if (bChan.discordAdminChannel > 0) { await SayOnDiscordAdmin(bChan, $"{args.userDisplayname} resubbed for a total of {args.monthsTotal} months and a streak of {args.monthsStreak} months."); } }
private string PubSubHelpDump(BotChannel bChan) { string twitchCheck = $"Currently this Discord is tied to the Twitch channel \"{bChan.TwitchChannelName}\""; if (bChan.TwitchChannelName == string.Empty) { twitchCheck = $"There is no twitch channel tied to this Discord. Use {CMC}twitch channel <CHANNELNAME> to set a channel."; } else { } string msg = $"```fix{System.Environment.NewLine}PubSub is how connections are made to Twitch to listen to events. This needs a valid token to work.{System.Environment.NewLine}" + $"Follow this link https://twitchtokengenerator.com/quick/YfuRoOx9WW to grab a token tied to your twitch account. It will only work on your channel and can be canceled through your Twitch settings page under Connections.{System.Environment.NewLine}" + $"Make sure to never share the Token with anyone.{System.Environment.NewLine}" + $"{System.Environment.NewLine}" + $"{twitchCheck}{System.Environment.NewLine}" + $"{System.Environment.NewLine}" + $"{CMC}pubsub is the base command.{System.Environment.NewLine}" + $"{System.Environment.NewLine}" + $"Arguments{System.Environment.NewLine}" + $"settoken <TOKEN> Use this to set the Token for the channel.{System.Environment.NewLine}" + $"cleartoken This removes any Token and shutsdown any running pubsub connection for the channel.{System.Environment.NewLine}"; msg += "```"; return(msg); }
private async void OnTwitchCommunitySubscription(BotChannel bChan, string message) { if (bChan.discordAdminChannel > 0) { await SayOnDiscordAdmin(bChan, message); } }
/// <summary> /// Fires when a raid notification is detected in chat /// </summary> private async void OnRaidNotification(object sender, OnRaidNotificationArgs e) { BotChannel bChan = await Program.Channels.GetTwitchChannelByName(e.Channel); int i = 0; int.TryParse(e.RaidNotification.MsgParamViewerCount, out i); Program.BotEvents.RaiseRaidEvent(bChan, new RaidEventArguments(e.RaidNotification.DisplayName, e.Channel, i)); }
/// <summary> /// Call this to get a list string wrapped in code flags for monospace layout returned with the fitting results. /// NOTE! Topic not implemneted yet TODO /// </summary> /// <param name="bChan"></param> /// <param name="page"></param> /// <param name="topic"></param> /// <returns></returns> internal async Task <string> GetPage(BotChannel bChan, int page, string topic = "") // TODO make Topic work { StringBuilder text = new StringBuilder(); List <DBString> lines = GetRowsByTen(bChan, page); await Task.Run(() => { text.Append($"```fix{Environment.NewLine}"); text.Append($"<ID> <TOPIC> <INUSE> <TEXT> Page {page + 1}{Environment.NewLine}"); if (lines.Count == 0) { text.Append("No hits. Try a lower page number."); } else { foreach (DBString entry in lines) { text.Append(String.Format("{0,4}", entry._id)); text.Append(String.Format("{0,8}", entry._topic)); text.Append(String.Format("{0,7}", entry._inuse)); text.Append(" "); text.Append(entry._text); text.Append(Environment.NewLine); } } }); text.Append(Environment.NewLine); text.Append($"Use command {Program.CommandCharacter}{BASECOMMAND} <page> to list a page. Those marked with an X for INUSE are in rotation. Topic is what the text is used for."); text.Append($"```"); return(text.ToString()); }
private async void Client_OnBan(object sender, OnBanArgs e) { BotChannel bChan = await Program.Channels.GetTwitchChannelByName(_twitchChannelName); UserEntry mod = await Program.Users.GetUserByTwitchID(e.BannedByUserId); UserEntry BannedUser = await Program.Users.GetUserByTwitchID(e.BannedUserId); if (BannedUser != null) { await Core.LOG(new LogEntry(LOGSEVERITY.INFO, EXTENSIONNAME, $"{_twitchChannelName} :: {e.BannedBy} banned {BannedUser._twitchDisplayname} for \"{e.BanReason}\"" )); } BanEventArguments banEvent = new BanEventArguments( bChan, mod, BannedUser, Core.CurrentTime, 0, e.BanReason, true ); Program.BotEvents.RaiseBanEvent(banEvent); }
/// <summary> /// Drops the DB table TableName(bChan.Key) /// </summary> /// <param name="bChan"></param> /// <returns></returns> public async Task <bool> TableDrop(BotChannel bChan) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.CommandType = CommandType.Text; cmd.Connection = Core.Data; /*cmd.CommandText = $"PRAGMA foreign_keys = OFF" + * $" DROP TABLE IF EXISTS \"{TableName(bChan.Key)}\"" + * $" PRAGMA foreign_keys = ON"; */ //cmd.CommandText = $"PRAGMA foreign_keys = OFF DROP TABLE [IF EXISTS] \"{TableName(bChan.Key)}\" PRAGMA foreign_keys = ON"; cmd.CommandText = $"PRAGMA foreign_keys = OFF, DROP TABLE \"{TableName(bChan.Key)}\", PRAGMA foreign_keys = ON"; try { int i = await cmd.ExecuteNonQueryAsync(); i = 123; } catch (Exception e) { Console.WriteLine(e.ToString()); throw; } return(TableExists(TableName(bChan.Key))); } }
public static async Task <bool> RoleAddUser(BotChannel bChan, UserEntry user, string role) { IGuild iGuild = Program.DiscordClient.GetGuild(bChan.GuildID) as IGuild; if (iGuild == null) { return(false); } SocketRole sRole = iGuild.Roles.FirstOrDefault(x => x.Name == role) as SocketRole; if (sRole == null) { return(false); } RequestOptions options = new RequestOptions(); options.Timeout = 1000; options.RetryMode = RetryMode.RetryTimeouts; IGuildUser iUser = await iGuild.GetUserAsync(user._discordUID, CacheMode.AllowDownload, options); if (iUser == null) { return(false); } await iUser.AddRoleAsync(sRole as IRole); return(true); }
/// <summary> /// Retrieves string from DB table TableName(bChan.Key) by ID. /// </summary> /// <param name="bChan"></param> /// <param name="id"></param> /// <returns></returns> public async Task <DBString> GetStringByID(BotChannel bChan, int id) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.CommandType = CommandType.Text; cmd.Connection = Core.Data; cmd.CommandText = $"SELECT * FROM \"{TableName(bChan.Key)}\" WHERE ROWID IS @id"; cmd.Parameters.AddWithValue("@id", id); SQLiteDataReader result; try { result = cmd.ExecuteReader(); } catch (Exception) { await Core.LOG(new LogEntry(LOGSEVERITY.WARNING, PLUGINNAME + "DatabseStrings", $"Database query failed hard. ({cmd.CommandText})")); throw; } result.Read(); if (!result.HasRows) { return(null); } return(new DBString((int)result.GetInt64(0), result.GetBoolean(1), result.GetString(2), result.GetString(3))); } }
private void StopQueue(BotChannel bChan) { if (_queues.ContainsKey(bChan.Key)) { _queues.Remove(bChan.Key); } }
private int QueuedUserCount(BotChannel bChan) { if (HasActiveQueue(bChan)) { return(_queues[bChan.Key].Count); } return(0); }
private string NextInQueue(BotChannel bChan) { if (_queues.ContainsKey(bChan.Key)) { return($"{_queues[bChan.Key].PullnextInQueue()} you are up!"); } return($"Queue is empty. Use {CMC}aq to join queue and {CMC}lq to leave queue."); }
/// <summary> /// NuJuan verification in progress TODO! /// </summary> /// <param name="bChan"></param> /// <param name="user"></param> internal void RaiseOnTwitchFollow(BotChannel bChan, UserEntry user) { if (bChan != null && user != null) { Core.LOG(new LogEntry(LOGSEVERITY.INFO, "Events", $"({bChan.TwitchChannelName}) New twitch follower:{user._twitchDisplayname}")); OnTwitchFollow?.Invoke(bChan, user); } }
/// <summary> /// Removes 1 botchannel with twitchID from DB and saves the passed botchannel to DB. /// </summary> /// <param name="channel"></param> /// <returns></returns> public async Task <bool> SaveAsLinked(BotChannel channel) { if (await ChannelDataDeleteTwitchID(channel.TwitchChannelID)) { ChannelSave(channel); } return((await GetDiscordGuildbyID(channel.GuildID)).isLinked); }