Ejemplo n.º 1
0
        private async Task RunBotAsync()
        {
            MakeTConfig.CreateDiscord();
            botCgf = new TConfigFile("Bot_Settings.tcfg");

            var cfg = new DiscordConfiguration
            {
                Token     = botCgf.Read("Bot Token"),
                TokenType = TokenType.Bot,

                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true
            };

            Client        = new DiscordClient(cfg);
            Client.Ready += Client_Ready;
            // finally, let's connect and log in
            await Client.ConnectAsync();

            // and this is to prevent premature quitting
            await Task.Delay(-1);
        }
Ejemplo n.º 2
0
        public void Start()
        {
            MakeTConfig.CreateIRC();
            TConfigFile irc_config = new TConfigFile("IRC_Settings.tcfg");

            // UTF-8 test
            irc.Encoding = Encoding.UTF8;

            // wait time between messages, we can set this lower on own irc servers
            irc.SendDelay = 200;

            // we use channel sync, means we can use irc.GetChannel() and so on
            irc.ActiveChannelSyncing = true;

            // here we connect the events of the API to our written methods
            // most have own event handler types, because they ship different data
            irc.OnQueryMessage += new IrcEventHandler(OnQueryMessage);
            irc.OnError        += new ErrorEventHandler(OnError);
            irc.OnRawMessage   += new IrcEventHandler(OnRawMessage);
            irc.OnQuit         += new QuitEventHandler(OnQuit);


            string[] serverlist;
            // the server we want to connect to, could be also a simple string
            serverlist = new string[] { "irc.tesseract-game.net" };
            int    port    = 7000;
            string channel = "#general";

            try
            {
                // here we try to connect to the server and exceptions get handled
                irc.Connect(serverlist, port);
            }
            catch (ConnectionException e)
            {
                // something went wrong, the reason will be shown
                Logger.ERROR("Couldn't connect! Reason: " + e.Message);
            }

            try
            {
                // here we logon and register our nickname and so on
                irc.Login("Xelia", "Xelia", 1, "Xelia", "Oui donc");
                irc.RfcOper(irc_config.Read("Oper username"), irc_config.Read("Oper password"));
                // join the channel
                irc.RfcJoin(channel);
                irc.RfcJoin("#admin");
                new IRCAuth(irc);

                // here we tell the IRC API to go into a receive mode, all events
                // will be triggered by _this_ thread (main thread in this case)
                // Listen() blocks by default, you can also use ListenOnce() if you
                // need that does one IRC operation and then returns, so you need then
                // an own loop
                irc.Listen();

                // when Listen() returns our IRC session is over, to be sure we call
                // disconnect manually
                irc.Disconnect();
            }
            catch (ConnectionException)
            {
                // this exception is handled because Disconnect() can throw a not
                // connected exception
            }
            catch (Exception e)
            {
                // this should not happen by just in case we handle it nicely
                System.Console.WriteLine("Error occurred! Message: " + e.Message);
                System.Console.WriteLine("Exception: " + e.StackTrace);
            }
        }