public TwitchIrcConnection(ITwitchFactory factory, TwitchBot bot, bool whisperServer)
        {
            this.factory = factory;
            this.bot = bot;
            this.whisperServer = whisperServer;

            Reconnect();
        }
Example #2
0
        public bool LogIn(string user, string nick, string token, ILogger logger, TwitchBot bot)
        {
            try
            {
                //bot = new TwitchBot(new SQLiteConnection(new SQLitePlatformWin32(), "DotDotBot.db"), logger);

                IrcCredentials credentials;
                credentials = new IrcCredentials(token, user);
                bot.Connect(credentials);
            }
            catch
            {
                return false;
            }

            return true;
        }
Example #3
0
        public static void Main()
        {
            dynamic config = JObject.Parse(File.ReadAllText("config.json"));
            if (config == null) throw new InvalidOperationException("Failed parsing config.json");

            TwitchBot twitch = new TwitchBot();

            twitch.Connect((string) config.Username, (string) config.Oauth);
            twitch.ChatMessageReceived += (s, e) => Console.WriteLine($"|{e.Message.Channel}| <{e.Message.Username}> {e.Message.Text}");
            twitch.ChannelJoined += (s, e) => Console.WriteLine($"Joined: {e.Channel}");
            twitch.ChannelLeave += (s, e) => Console.WriteLine($"Left: {e.Channel}");

            twitch.JoinChannel("ssstormy");
            twitch.JoinChannel("discordrelay");

            twitch.Wait();
        }
Example #4
0
        static void Main(string[] args)
        {
            var logger = new ConsoleTraceLogger();
            logger.Write($"---- New log started {DateTime.UtcNow} UTC ----");
            try
            {
                logger.Write($"DotDotBot Console version {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion} started.");

                var config = new ProgramConfig();

                var pluginManager = new PluginManager();
                var bot = new TwitchBot(new SQLiteConnection(new SQLitePlatformWin32(), "DotDotBot.db"), pluginManager, logger, config.BotOwner);

                if (!File.Exists("config.json"))
                {
                    logger.Write("Could not find config.json Please edit config_example.json and rename it to config.json");
            #if DEBUG
                    System.Console.ReadKey();
            #endif
                    return;
                }

                bot.IrcClient.AutoJoinChannels = config.AutoJoinChannels;
                bot.Connect(config.Credentials);
            }
            catch (ReflectionTypeLoadException e)
            {
                logger.Write($"Exception: {e.Message}");
                logger.Write($"LoaderExceptions:");
                foreach (var loaderException in e.LoaderExceptions)
                {
                    logger.WriteIndented($"-> {loaderException.Message}");
                }
                logger.WriteIndented($"Stacktrace: { e.StackTrace}");
                throw;
            }
            catch (Exception e)
            {
                logger.Write($"Exception: {e.Message}");
                logger.WriteIndented($"Stacktrace: { e.StackTrace}");
                throw;
            }

            logger.Write("Press Q to quit program.");
            while (!System.Console.ReadKey().Key.Equals(ConsoleKey.Q));
        }
Example #5
0
 static string GetJson(TwitchBot bot, uint limit, uint offset, string path)
 {
     return WebClient.GetHTML("https://api.twitch.tv/kraken/" + path + "&oauth_token=" + bot.oauthPassword + "&limit=" + limit
         + "&offset=" + offset);
 }
 public TwitchConnection[] GetAllAutoConnectingConnections(TwitchBot bot)
 {
     return SqlTwitchConnection.GetAllAutoConnectingConnections(bot);
 }
Example #7
0
        void IModule.Install(ModuleManager manager)
        {
            _client = manager.Client;
            _twitch = new TwitchBot();

            manager.CreateDynCommands("twitch", PermissionLevel.ChannelModerator, group =>
            {
                group.CreateCommand("connect")
                    .Description("Connects this channel to a given twitch channel, relaying the messages between them.")
                    .Parameter("channel")
                    .Do(async e =>
                    {
                        string channel = e.GetArg("channel");

                        if (await IsValidTwitchChannelAndIsStreaming(channel))
                        {
                            int? viewers = await GetViewerCount(channel);

                            if (viewers != null && viewers.Value <= MaxViewsPerChannel)
                                await Subscribe(channel, e.Channel);
                            else
                                await
                                    e.Channel.SafeSendMessage(
                                        $"{channel}'s view count ({viewers}) is currently over the view barrier ({MaxViewsPerChannel}), therefore, for the sake of not getting a cooldown for spamming Discord, we cannot connect to this channel.");
                        }
                        else
                            await e.Channel.SafeSendMessage($"{channel} channel is currently offline.");
                    });

                group.CreateCommand("disconnect")
                    .Description("Disconnects this channel from the given twitch channel.")
                    .Parameter("channel")
                    .Do(async e => { await Unsubscribe(e.GetArg("channel"), e.Channel); });
                group.CreateCommand("list")
                    .MinDynPermissions((int) PermissionLevel.User)
                    .Description("Lists all the twitch channels this discord channel is connected to.")
                    .Do(async e =>
                    {
                        List<string> twitchSub = GetTwitchChannels(e.Channel).ToList();

                        if (!twitchSub.Any())
                        {
                            await e.Channel.SafeSendMessage("This channel isin't subscribed to any twitch channels.");
                            return;
                        }

                        StringBuilder builder = new StringBuilder($"**{e.Channel.Name} is subscribed to:**\r\n```");
                        foreach (string twitchChannel in twitchSub)
                            builder.AppendLine($"* {twitchChannel}");

                        await e.Channel.SafeSendMessage($"{builder.ToString()}```");
                    });
            });

            _twitch.DisconnectFromTwitch +=
                async (s, e) =>
                {
                    Logger.FormattedWrite("Twitch", "Disconnected from twitch", ConsoleColor.Red);

                    // try to reconnect to twitch
                    while (!_twitch.IsConnected)
                    {
                        Logger.FormattedWrite("Twitch", "Attempting to reconnect to twitch...", ConsoleColor.Red);
                        await TwitchTryConnect();
                        await Task.Delay(5000);
                    }

                    Logger.FormattedWrite("Twitch", "Reconnected to twitch.", ConsoleColor.Red);
                };

            _twitch.ChatMessageReceived += async (s, e) =>
            {
                if (!_relays.ContainsKey(e.Message.Channel)) return;
                if (e.Message.Username == Config.TwitchUsername) return;

                if (e.Message.Text.StartsWith(EscapePrefix)) return;

                foreach (JsonChannel relay in _relays[e.Message.Channel])
                    await relay.Channel.SafeSendMessage($"**Twitch**: `<{e.Message.Username}> {e.Message.Text}`");
            };

            _twitch.ChannelLeave += (s, e) => _relays.Remove(e.Channel);

            _client.MessageReceived += (s, e) =>
            {
                if (e.Message.IsAuthor) return;
                if (e.Message.Text.StartsWith(EscapePrefix)) return;

                foreach (string twitchChannel in GetTwitchChannels(e.Channel))
                    _twitch.SendMessage(twitchChannel, $"{e.User.Name}@{e.Channel.Name}: {e.Message.Text}");
            };
        }