Exemplo n.º 1
0
        public string RegisterUser(IrcCommand command)
        {
            userdb.RegisterUser(command.Source.Nick, command.Parameters[0], command.Source.Hostmask);
            SaveDB();

            return "Done.  Your password is stored with SHA256";
        }
Exemplo n.º 2
0
        public string DiffManifests(IrcCommand command)
        {
            if (command.Parameters.Length > 2) return ".diffmanifests <manifest1> <manifest2>.";
            string directory = "output/";
            if(!Directory.Exists(directory + "Diffs/")) Directory.CreateDirectory(directory + "Diffs/");

            string outputfilename = command.Source.Nick + "diff";
            while (System.IO.File.Exists(directory + "Diffs/" + outputfilename + ".html"))
            {
                outputfilename += "_";
            }

            string f1 = command.Parameters[0];
            string f2 = command.Parameters[1];

            string output = Util.DiffTwoFiles(directory + "Manifests/" + f1, directory + "Manifests/" + f2);

            using (StreamWriter wr = new StreamWriter(directory + "Diffs/" + outputfilename + ".html"))
            {
                wr.Write(output);
            }

            Timer t = new Timer(1000 * 60 * 5);
            t.Elapsed += new ElapsedEventHandler((o, e) =>
            {
                System.IO.File.Delete(directory + "Diffs/" + outputfilename + ".html");
                SendMessage("#reside_priv", outputfilename + ".html has expired");
            });

            return "Done: " + string.Format("http://www.testoutfit.info/lebot/Diffs/{0}.html", outputfilename);
        }
Exemplo n.º 3
0
        public string SendMessage(IrcCommand command)
        {
            string username = command.Parameters[0];
            string message = command.Message.Remove(0, username.Length + 1);
            message = "From " + command.Source.Nick + " on " + DateTime.Now.ToString() + ": " + message;

            return SendMemo(username, message) ? "Message Sent" : "User does not exist";
        }
Exemplo n.º 4
0
        public string ToggleSysMessageRecieve(IrcCommand command)
        {
            User user = userdb.GetUserByNameHost(command.Source.Nick, command.Source.Hostmask);
            if (user == null) return "You are not registered.  Send me a query with '.register <password>' so I know who you are";

            userdb.ToggleSysMessages(user);
            SaveDB();
            return "Done";
        }
Exemplo n.º 5
0
        public string QueryStats(IrcCommand command)
        {
            JObject o = GetUserJsonData(command.Parameters[0].ToLower());

            JToken charlist = o["character_list"];
            if (!charlist.HasValues) return "Character Not Found";

            StringBuilder builder = new StringBuilder();

            JToken token = charlist.First["outfit"];

            if (charlist.First["outfit"] != null)
            {
                builder.Append("[");
                builder.Append((string)charlist.First["outfit"]["alias"]);
                builder.Append("] ");
            }
            builder.Append((string)charlist.First["name"]["first"]);
            builder.Append(" is part of ");
            int id = 0;
            bool success = int.TryParse((string)charlist.First["world_id"], out id);
            if (!success)
            {
                return "World ID is not a number.  Character probably banned, deleted, or duplicate name in the api";
            }
            builder.Append(worlds[int.Parse((string)charlist.First["world_id"])]);

            builder.Append("'s ");

            String faction = (string)charlist.First["type"]["faction"];
            switch (faction)
            {
                case "vs":
                    faction = "Vanu Sovereignty";
                    break;
                case "tr":
                    faction = "Terran Republic";
                    break;
                case "nc":
                    faction = "New Conglomerate";
                    break;
            }

            builder.Append(faction);

            //string name = (string)o["character_list"]["name"]["first"];

            return builder.ToString();
        }
Exemplo n.º 6
0
        public string DownloadStatus(IrcCommand command)
        {
            //if (command.Destination != "#reside_priv") return "NOPERM";
            int jobs = Downloader.DownloadJobsToComplete();
            if (jobs == 0) return "No Downloads In Progress.";

            string[] Statusii = Downloader.ReportDownloadStatus();
            if (Statusii.Length > 5) return "Done: " + string.Join("\n", Statusii).Haste();

            foreach (string s in Statusii)
            {
                SendMessage(command.Destination, s);
            }
            return "Done.";
        }
Exemplo n.º 7
0
        public string AddCaptcha(IrcCommand command)
        {
            if (!AccessCheck(command)) return "No Permision";

            if (command.Parameters.Length != 1 || !command.Parameters[0].Contains("hastebin.com/raw/")) return "'.addcaptcha <hastebinlink>'  First line should be the captcha, second line the answer";

            string data = QuickDownload(command.Parameters[0]);

            string[] spl = data.Split('\n');

            Settings.VDCCaptchas[spl[0]] = spl[1];

            Settings.Save();

            return "Added";
        }
Exemplo n.º 8
0
        public string CalculateRevisionOLD(IrcCommand command)
        {
            if (!RevDBs[CurrentBranchOLD].RevisionOpen) return "No Revision Open";

            using (StreamReader reader = new StreamReader(command.Parameters[0]))
            {
                while (!reader.EndOfStream)
                {
                    string[] revdata = reader.ReadLine().Split('\t');
                    RevDBs[CurrentBranchOLD].CalculateRevision(revdata[0], ulong.Parse(revdata[2]), int.Parse(revdata[1]));

                }
                RevDBs[CurrentBranchOLD].CheckForRemovedFile();

            }

            return "Done";
        }
Exemplo n.º 9
0
        private string DoYoutube(IrcCommand command)
        {
            string vid;
            if (command.Parameters.Length != 1)
            {
                var results = DoGoogleSearch("site:youtube.com " + command.Message);
                if (results.Count == 0)
                    return "No results found.";
                else
                    vid = results.First().Substring(results.First().LastIndexOf("http://"));
            }
            else
                vid = command.Parameters[0];
            if (Uri.IsWellFormedUriString(vid, UriKind.Absolute))
            {
                Uri uri = new Uri(vid);
                var query = HttpUtility.ParseQueryString(uri.Query);
                vid = query["v"];
                if (vid == null)
                    return "Video not found.";
            }
            var video = GetYoutubeVideo(vid);
            if (video == null)
                return "Video not found.";

            string partOne = "\"\u0002" + video.Title + "\u000f\" [" +
                video.Duration.ToString("m\\:ss") + "] (\u000312" + video.Author + "\u000f)\u000303 " +
                (video.HD ? "HD" : "SD");

            string partTwo = video.Views.ToString("N0", CultureInfo.InvariantCulture) + " views";
            if (video.RatingsEnabled)
                partTwo += ", " +
                    "(+\u000303" + video.Likes.ToString("N0", CultureInfo.InvariantCulture) +
                    "\u000f|-\u000304" + video.Dislikes.ToString("N0", CultureInfo.InvariantCulture) + "\u000f) [" + video.Stars + "]";

            if (video.RegionLocked | !video.CommentsEnabled || !video.RatingsEnabled)
            {
                partTwo += " ";
                if (video.RegionLocked)
                    partTwo += "\u000304Region locked\u000f, ";
                if (!video.CommentsEnabled)
                    partTwo += "\u000304Comments disabled\u000f, ";
                if (!video.RatingsEnabled)
                    partTwo += "\u000304Ratings disabled\u000f, ";
                partTwo = partTwo.Remove(partTwo.Length - 3);
            }

            if (partOne.Length < partTwo.Length)
                partOne += "\u000f " + video.VideoUri.ToString();
            else
                partTwo += "\u000f " + video.VideoUri.ToString();

            SendMessage(command.Destination, partOne);
            SendMessage(command.Destination, partTwo);

            return null;
        }
Exemplo n.º 10
0
 private string DoWikipedia(IrcCommand command)
 {
     if (string.IsNullOrEmpty(command.Message))
         return null;
     var results = DoGoogleSearch("site:en.wikipedia.org " + command.Message);
     if (results.Count == 0)
         return "No results found.";
     else
         return results.First();
 }
Exemplo n.º 11
0
 private string DoTopic(IrcCommand command)
 {
     if (command.Parameters.Length == 0)
         return null;
     this.ChanServ.TempOp(command.Destination, () =>
         {
             this.Topic(command.Destination, command.Message);
         });
     return null;
 }
Exemplo n.º 12
0
 private string DoStatus(IrcCommand command)
 {
     var status = GetMojangStatus();
     return "\u000fWebsite: " + (status.Website ? "\u000303ONLINE" : "\u000305OFFLINE") +
         "\u000f | Login: "******"\u000303ONLINE" : "\u000305OFFLINE") +
         "\u000f | Session: " + (status.Session ? "\u000303ONLINE" : "\u000305OFFLINE") +
         "\u000f | Accounts: " + (status.Account ? "\u000303ONLINE" : "\u000305OFFLINE") +
         "\u000f | Authentication: " + (status.Authentication ? "\u000303ONLINE" : "\u000305OFFLINE");
 }
Exemplo n.º 13
0
 private string DoSearch(IrcCommand command)
 {
     if (command.Parameters.Length == 0)
         return null;
     var results = DoGoogleSearch(command.Message);
     if (results.Count == 0)
         return "No results found.";
     else
         return results.First();
 }
Exemplo n.º 14
0
 private string DoPing(IrcCommand command)
 {
     if (command.Parameters.Length == 0)
         return "pong";
     else if (command.Parameters.Length == 1)
     {
         try
         {
             var server = MinecraftServer.GetServer(command.Parameters[0]);
             if (server.IsOnline)
             {
                 return "\u000303ONLINE\u000F [" + server.ConnectedPlayers +
                     "/" + server.MaxPlayers + "]: " + server.MotD;
             }
             else
                 return "\u000305OFFLINE";
         }
         catch
         {
             return "\u000305OFFLINE";
         }
     }
     else
         return null;
 }
Exemplo n.º 15
0
 private string DoMwiki(IrcCommand command)
 {
     if (string.IsNullOrEmpty(command.Message))
         return null;
     var results = DoGoogleSearch("site:minecraftwiki.net " + command.Message);
     if (results.Count == 0)
         return "No results found.";
     else
         return results.First();
 }
Exemplo n.º 16
0
 public CommandEventArgs(IrcCommand command)
 {
     Command = command;
 }
Exemplo n.º 17
0
 private string DoKick(IrcCommand command)
 {
     if (command.Parameters.Length == 0)
         return null;
     this.ChanServ.TempOp(command.Destination, () =>
         {
             if (command.Parameters.Length == 1)
                 this.Kick(command.Destination, command.Parameters[0], "Requested by " + command.Source.Nick);
             else
                 this.Kick(command.Destination, command.Parameters[0],
                     command.Message.Substring(command.Message.IndexOf(' ') + 1));
         });
     return null;
 }
Exemplo n.º 18
0
        private void HandleMessage(IrcMessage message)
        {
            // scope in switch...case is stupid in C#
            string     raw, channelName, reason;
            IrcChannel channel;

            switch (message.Command)
            {
            case "001":
                if (ConnectionComplete != null)
                {
                    ConnectionComplete(this, null);
                }
                break;

            case "PRIVMSG":
                IrcCommand     command     = null;
                IrcUserMessage userMessage = new IrcUserMessage(message);
                if (UserMessageRecieved != null)
                {
                    UserMessageRecieved(this, new UserMessageEventArgs(userMessage));
                }
                string messagePrepend = "", destination = userMessage.Target;
                string sourceNick = userMessage.Source.Nick;
                if (userMessage.Message.Contains("@"))
                {
                    sourceNick          = userMessage.Message.Substring(userMessage.Message.IndexOf("@") + 1).Trim();
                    userMessage.Message = userMessage.Message.Remove(userMessage.Message.IndexOf("@"));
                }
                if (message.Payload.StartsWith("#"))     // channel message
                {
                    messagePrepend = sourceNick + ": \u000f";
                }
                if (userMessage.Message.StartsWith(ControlCharacter))
                {
                    command             = new IrcCommand(userMessage.Source, userMessage.Message.Trim(), messagePrepend);
                    command.Destination = destination;
                    if (RegisteredCommands.ContainsKey(command.Command.ToLower()))
                    {
                        Thread tempThread = new Thread(() =>
                        {
                            try
                            {
                                if (PreCommand != null)
                                {
                                    var eventArgs = new CommandEventArgs(command);
                                    PreCommand(this, eventArgs);
                                    command = eventArgs.Command;
                                }
                                string response = RegisteredCommands[command.Command.ToLower()](command);
                                if (response != null)
                                {
                                    SendMessage(destination, messagePrepend + response);
                                }
                                if (PostCommand != null)
                                {
                                    PostCommand(this, new CommandEventArgs(command));
                                }
                            }
                            catch (Exception e) {
                                SendMessage(destination, messagePrepend + "Error: " + e.ToString().Haste());
                            }
                        });
                        tempThread.Start();
                    }
                }
                break;

            case "PING":
                SendRawMessage("PONG " + message.Payload);
                ServerPingAddress = message.Payload;
                LastPingRecieved  = DateTime.Now;
                break;

            case "PONG":
                LastPongRecieved = DateTime.Now;
                break;

            case "332":     // Channel topic
                raw           = message.Payload.Substring(message.Payload.IndexOf(' ') + 1);
                channelName   = raw.Remove(raw.IndexOf(' '));
                raw           = raw.Substring(raw.IndexOf(' ') + 1).Substring(1);
                channel       = GetChannel(channelName);
                channel.Topic = raw;
                break;

            case "353":
                raw         = message.Payload.Substring(message.Payload.IndexOf(' ') + 3);
                channelName = raw.Remove(raw.IndexOf(' '));
                raw         = raw.Substring(raw.IndexOf(':') + 1);
                string[] names = raw.Split(' ');
                channel = GetChannel(channelName);
                foreach (var user in names)
                {
                    if (user.StartsWith("+"))
                    {
                        channel.Users.Add(user.Substring(1));
                    }
                    else if (user.StartsWith("@"))
                    {
                        channel.Users.Add(user.Substring(1));
                    }
                    else
                    {
                        channel.Users.Add(user);
                    }
                }
                break;

            case "366":     // End of names
                raw         = message.Payload.Substring(message.Payload.IndexOf(' ') + 1);
                channelName = raw.Remove(raw.IndexOf(' '));
                if (ChannelListRecieved != null)
                {
                    ChannelListRecieved(this, new ChannelListEventArgs(GetChannel(channelName)));
                }
                break;

            case "MODE":
                if (message.Payload.StartsWith("#"))
                {
                    ChannelModeChangeEventArgs eventArgs = new ChannelModeChangeEventArgs();
                    eventArgs.Source     = new IrcUser(message.Prefix);
                    eventArgs.Channel    = GetChannel(message.Payload.Remove(message.Payload.IndexOf(' ')));
                    eventArgs.ModeChange = message.Payload.Substring(message.Payload.IndexOf(' ') + 1);
                    if (ChannelModeChanged != null)
                    {
                        ChannelModeChanged(this, eventArgs);
                    }
                }
                break;

            case "NOTICE":
                if (NoticeRecieved != null)
                {
                    NoticeRecieved(this, new NoticeEventArgs(new IrcNotice(message)));
                }
                break;

            case "PART":
                // #IAmABotAMA :\"hello world\"
                channelName = message.Parameters[0];
                channel     = GetChannel(channelName);
                reason      = message.Payload.Substring(message.Payload.IndexOf(':') + 1);
                if (new IrcUser(message.Prefix).Nick != User.Nick)
                {
                    channel.Users.Remove(new IrcUser(message.Prefix).Nick);
                    if (UserPartedChannel != null)
                    {
                        UserPartedChannel(this, new UserPartEventArgs(new IrcUser(message.Prefix), channel, reason));
                    }
                }
                break;

            case "JOIN":
                channelName = message.Parameters[0];
                channel     = GetChannel(channelName);
                channel.Users.Add(new IrcUser(message.Prefix).Nick);
                if (UserJoinedChannel != null)
                {
                    UserJoinedChannel(this, new UserJoinEventArgs(new IrcUser(message.Prefix), channel));
                }
                break;

            case "QUIT":
                reason = message.Payload.Substring(message.Payload.IndexOf(':') + 1);
                if (new IrcUser(message.Prefix).Nick != User.Nick)
                {
                    foreach (var c in Channels)
                    {
                        if (c.Users.Contains(new IrcUser(message.Prefix).Nick))
                        {
                            c.Users.Remove(new IrcUser(message.Prefix).Nick);
                        }
                    }
                    if (UserQuit != null)
                    {
                        UserQuit(this, new UserQuitEventArgs(new IrcUser(message.Prefix), reason));
                    }
                }
                else
                {
                    if (ServerQuit != null)
                    {
                        ServerQuit(this, null);
                    }
                    // Reconnect
                    if (IrcConnection.Connected)
                    {
                        IrcConnection.Disconnect(false);
                    }
                    IrcConnection   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    ReadBuffer      = new byte[1024];
                    ReadBufferIndex = 0;
                    IrcConnection.BeginConnect(ServerHostname, ServerPort, ConnectComplete, null);
                }
                break;

            case "311":     // WHOIS response
                string[] whois  = message.Payload.Split(' ');
                var      result = new IrcUser(whois[1], whois[2].Substring(1));
                result.Hostname = whois[3];
                if (WhoIsCallback != null)
                {
                    WhoIsCallback(result);
                    WhoIsCallback = null;
                }
                break;

            case "TOPIC":
                if (TopicCallback != null)
                {
                    TopicCallback(message.Payload.Substring(message.Payload.IndexOf(":") + 1));
                    TopicCallback = null;
                }
                break;

            case "NICK":
                if (NickChanged != null)
                {
                    NickChanged(this, new NickChangedEventArgs(new IrcUser(message.Prefix), message.Payload));
                }
                break;
            }
        }
Exemplo n.º 19
0
 private string DoOp(IrcCommand command)
 {
     if (command.Parameters.Length == 0)
         this.ChanServ.Op(command.Destination, command.Source.Nick);
     else if (command.Parameters.Length == 1)
         this.ChanServ.Op(command.Destination, command.Parameters[0]);
     return null;
 }
Exemplo n.º 20
0
 private string DoDown(IrcCommand command)
 {
     if (command.Parameters.Length != 1)
         return null;
     try
     {
         HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(
             new Uri(FormatHttpUri(command.Parameters[0])));
         hwr.Timeout = 3000;
         var response = (HttpWebResponse)hwr.GetResponse();
         if (response.StatusCode == HttpStatusCode.OK)
             return "Looks up to me";
         else
             return "Looks down to me";
     }
     catch
     {
         return "Looks down to me";
     }
 }
Exemplo n.º 21
0
 private string DoReaders(IrcCommand command)
 {
     if (command.Parameters.Length != 1)
         return null;
     string subreddit = command.Parameters[0];
     if (subreddit.StartsWith("r/"))
         subreddit = subreddit.Substring(2);
     if (subreddit.StartsWith("/r/"))
         subreddit = subreddit.Substring(3);
     var result = GetSubreddit(subreddit);
     return "/r/" + subreddit + " has " + result.Readers.ToString("N0", CultureInfo.InvariantCulture) +
                     " readers. http://reddit.com/r/" + subreddit + (result.NSFW ? " \u000305NSFW" : "");
 }
Exemplo n.º 22
0
 private string DoEcho(IrcCommand command)
 {
     this.SendMessage(command.Destination, command.Message);
     return null;
 }
Exemplo n.º 23
0
 private string DoServers(IrcCommand command)
 {
     if (command.Parameters.Length != 0)
         return null;
     // TODO: These might not work on the live server
     var factions = MinecraftServer.GetServer("216.185.144.243");
     var hardsurvival = MinecraftServer.GetServer("216.185.144.245");
     var freebuild = MinecraftServer.GetServer("216.185.144.242");
     return "hardsurvival.badass-gaming.com: " + (hardsurvival.IsOnline ? "\u000303ONLINE \u000f[" + hardsurvival.ConnectedPlayers + "/" + hardsurvival.MaxPlayers + "]" : "\u000305OFFLINE") +
             "\u000f | factions.badass-gaming.com: " + (factions.IsOnline ? "\u000303ONLINE \u000f[" + factions.ConnectedPlayers + "/" + factions.MaxPlayers + "]" : "\u000305OFFLINE") +
             "\u000f | freebuild.badass-gaming.com: " + (freebuild.IsOnline ? "\u000303ONLINE \u000f[" + freebuild.ConnectedPlayers + "/" + freebuild.MaxPlayers + "]" : "\u000305OFFLINE");
 }
Exemplo n.º 24
0
 private string DoHug(IrcCommand command)
 {
     if (command.Parameters.Length == 0)
         SendAction(command.Destination, "hugs " + command.Source.Nick);
     else if (command.Parameters.Length == 1)
         SendAction(command.Destination, "hugs " + command.Parameters[0]);
     return null;
 }
Exemplo n.º 25
0
 private string DoTitle(IrcCommand command)
 {
     if (command.Parameters.Length != 1)
         return null;
     return FetchPageTitle(FormatHttpUri(command.Message)) ?? "Unable to fetch title.";
 }
Exemplo n.º 26
0
 private string DoIdentify(IrcCommand command)
 {
     NotifyVerification.Add(command.Source.Nick);
     this.SendMessage("NickServ", "ACC " + command.Source.Nick);
     return null;
 }
Exemplo n.º 27
0
 private string DoTwitter(IrcCommand command)
 {
     if (command.Parameters.Length != 1) // TODO: Expand this function
         return null;
     return GetTweet(command.Parameters[0]);
 }
Exemplo n.º 28
0
 private string DoInvite(IrcCommand command)
 {
     if (command.Parameters.Length != 1)
         return null;
     this.ChanServ.TempOp(command.Destination, () =>
         {
             this.Invite(command.Destination, command.Parameters[0]);
         });
     return null;
 }
Exemplo n.º 29
0
 private string DoXkcd(IrcCommand command)
 {
     if (string.IsNullOrEmpty(command.Message))
         return null;
     var results = DoGoogleSearch("site:xkcd.com " + command.Message);
     if (results.Count == 0)
         return "No results found.";
     else
         return results.First();
 }
Exemplo n.º 30
0
 private string DoJoin(IrcCommand command)
 {
     if (command.Parameters.Length != 1)
         return null;
     if (!command.Parameters[0].StartsWith("#"))
         return null;
     JoinChannel(command.Parameters[0]);
     return null;
 }
Exemplo n.º 31
0
 private string HandleManagerCommand(IrcCommand command)
 {
     if (!Managers.Contains(command.Source.Nick)) // Check for manager
         return null;
     if (!VerifiedUsers.Contains(command.Source.Nick)) // Check for verification
     {
         // Verify and postpone command if needed
         IdentifyUser(command.Source.Nick, new CommandPendingID()
         {
             Callback = HandleManagerCommand,
             Command = command
         });
         return null;
     }
     // Execute command
     var resp = ManagerCommands[command.Command](command);
     if (resp != null)
         this.SendMessage(command.Destination, command.Prefix + resp);
     return null;
 }
Exemplo n.º 32
0
 private string DoKarma(IrcCommand command)
 {
     if (command.Parameters.Length != 1)
         return null;
     var karma = GetUserKarma(command.Parameters[0]);
     return command.Parameters[0] + " has " +
         karma.LinkKarma.ToString("N0", CultureInfo.InvariantCulture) +
         " link karma and " + karma.CommentKarma.ToString("N0", CultureInfo.InvariantCulture) + " comment karma after " +
         GetDuration(karma.Created) + ". http://reddit.com/u/" + command.Parameters[0];
 }