/// <summary> /// Actual command logic /// </summary> /// <param name="source">The user who triggered the command.</param> /// <param name="channel">The channel the command was triggered in.</param> /// <param name="args">The arguments to the command.</param> /// <returns></returns> protected override CommandResponseHandler execute(User source, string channel, string[] args) { bool useLongInfo = bool.Parse(Configuration.singleton()["useLongUserInfo", channel]); if (args.Length > 0) { if (args[0].ToLower() == "@long") { useLongInfo = true; GlobalFunctions.popFromFront(ref args); } if (args[0].ToLower() == "@short") { useLongInfo = false; GlobalFunctions.popFromFront(ref args); } } if (args.Length > 0) { string userName = string.Join(" ", args); UserInformation uInfo = new UserInformation(); Editcount countCommand = new Editcount(); uInfo.editCount = countCommand.getEditCount(userName, channel); if (uInfo.editCount == -1) { string[] mparams = { userName }; this._crh.respond(new Message().get("noSuchUser", mparams)); return(this._crh); } retrieveUserInformation(userName, ref uInfo, channel); //################################################## if (useLongInfo) { sendLongUserInfo(uInfo); } else { sendShortUserInfo(uInfo); } } else { string[] messageParameters = { "userinfo", "1", args.Length.ToString() }; Helpmebot6.irc.ircNotice(source.nickname, new Message().get("notEnoughParameters", messageParameters)); } return(this._crh); }
//TODO: tidy up! why return a value when it's passed by ref anyway? // ReSharper disable UnusedMethodReturnValue.Local /// <summary> /// Retrieves the user information. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="initial">The initial.</param> /// <param name="channel">The channel.</param> /// <returns></returns> private static UserInformation retrieveUserInformation(string userName, ref UserInformation initial, string channel) // ReSharper restore UnusedMethodReturnValue.Local { try{ initial.userName = userName; if (initial.editCount == 0) { Editcount countCommand = new Editcount(); initial.editCount = countCommand.getEditCount(userName, channel); } Rights rightsCommand = new Rights(); initial.userGroups = rightsCommand.getRights(userName, channel); Registration registrationCommand = new Registration(); initial.registrationDate = registrationCommand.getRegistrationDate(userName, channel); initial.userPage = getUserPageUrl(userName, channel); initial.talkPage = getUserTalkPageUrl(userName, channel); initial.userContribs = getUserContributionsUrl(userName, channel); initial.userBlockLog = getBlockLogUrl(userName, channel); Age ageCommand = new Age(); initial.userAge = ageCommand.getWikipedianAge(userName, channel); initial.editRate = initial.editCount / initial.userAge.TotalDays; Blockinfo.BlockInformation bi = new Blockinfo().getBlockInformation(userName, channel); if (bi.id == null) { initial.blockInformation = ""; } else { initial.blockInformation = bi.id.ToString(); } return(initial); } catch (NullReferenceException ex) { GlobalFunctions.errorLog(ex); throw new InvalidOperationException(); } }