Ejemplo n.º 1
0
 public bool IsExistingUsername0(string fullname)
 {
     //lock (BotUsers)
     {
         fullname = CleanupFromname(fullname);
         if (null == fullname)
         {
             return(false);
         }
         String fromname = CleanupFromname(fullname);
         if (string.IsNullOrEmpty(fromname))
         {
             return(false);
         }
         String key = KeyFromUsername(fullname);
         User   user;
         lock (microBotUsersLock) if (BotUsers.TryGetValue(key, out user))
             {
                 if (user.UserID == key || user.UserID == fromname)
                 {
                     return(true);
                 }
                 writeToLog("WARNING! {0} => {1} <= {2}", fromname, key, user.UserID);
                 return(true);
             }
         return(false);
     }
 }
Ejemplo n.º 2
0
        internal bool RemoveUser0(string name)
        {
            string keyname = KeyFromUsername(name);
            User   user    = null;

            {
                if (TryGetValueLocked(microBotUsersLock, BotUsers, name, out user))
                {
                    user.DisposeObject();
                    lock (microBotUsersLock) BotUsers.Remove(name);
                    writeToUserLog("REMOVED " + name);
                }
                if (TryGetValueLocked(microBotUsersLock, BotUsers, keyname, out user))
                {
                    user.DisposeObject();
                    lock (microBotUsersLock) BotUsers.Remove(keyname);
                    writeToUserLog("REMOVED " + keyname);
                }
                else
                {
                    writeToUserLog("rmuser, No user by the name ='" + name + "'");
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        public void setBotMode()
        {
            bot = true;
            string base_path = Path.Combine(FriendList.accountsPath, Base58Check.Base58CheckEncoding.EncodePlain(walletAddress));

            users = new BotUsers(Path.Combine(base_path, "contacts.dat"), null, true);
            users.loadContactsFromFile();
            groups = new BotGroups(Path.Combine(base_path, "groups.dat"));
            groups.loadGroupsFromFile();
            channels = new BotChannels(Path.Combine(base_path, "channels.dat"));
            channels.loadChannelsFromFile();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// добавить или обновить пользователя бота
        /// </summary>
        /// <param name="botUsers"></param>
        /// <returns></returns>
        internal BotUsers AddOrUpdateBotUsers(BotUsers botUsers)
        {
            BotUsers usr = data.GetTable <BotUsers>().FirstOrDefault(x => x.TlgUserId == botUsers.TlgUserId);

            if (usr == null)
            {
                data.GetTable <BotUsers>().InsertOnSubmit(botUsers);
                data.SubmitChanges();
                usr = data.GetTable <BotUsers>().FirstOrDefault(x => x.TlgUserId == botUsers.TlgUserId);
            }
            else
            {
                usr           = data.GetTable <BotUsers>().Where(x => x.TlgUserId == botUsers.TlgUserId).ToList()[0];
                usr.LastEnter = DateTime.Now;
                data.SubmitChanges();
            }
            return(usr);
        }
Ejemplo n.º 5
0
        // Perform basic initialization of node
        private void init()
        {
            running = true;

            CoreConfig.maximumServerMasterNodes = Config.maximumStreamClients;
            CoreConfig.maximumServerClients     = Config.maximumStreamClients;

            UpdateVerify.init(Config.checkVersionUrl, Config.checkVersionSeconds);

            // Network configuration
            NetworkUtils.configureNetwork(Config.externalIp, Config.serverPort);

            // Load or Generate the wallet
            if (!initWallet())
            {
                running = false;
                SpixiBot.Program.noStart = true;
                return;
            }

            // Setup the stats console
            statsConsoleScreen = new StatsConsoleScreen();

            PeerStorage.init("");

            // Init TIV
            tiv = new TransactionInclusion();

            string avatarPath = Path.Combine(Config.dataDirectory, "Avatars");

            users = new BotUsers(Path.Combine(Config.dataDirectory, "contacts.dat"), avatarPath, false);
            users.loadContactsFromFile();

            groups = new BotGroups(Path.Combine(Config.dataDirectory, "groups.dat"));
            groups.loadGroupsFromFile();

            channels = new BotChannels(Path.Combine(Config.dataDirectory, "channels.dat"));
            channels.loadChannelsFromFile();

            StreamProcessor.init(Path.Combine(Config.dataDirectory, "Messages"));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// добавить строку в протокол
        /// </summary>
        /// <param name="tlgUserId"></param>
        /// <param name="tlgUserName"></param>
        /// <returns></returns>
        internal BotUsers AddOrUpdateBotUsers(int tlgUserId, long tlgChatId, string tlgUserName)
        {
            BotUsers botUsers = new BotUsers()
            {
                BestResult = 0, FirstEnter = DateTime.Now, LastEnter = DateTime.Now, TlgUserId = tlgUserId, TlgChatId = tlgChatId, TlgUserName = tlgUserName
            };
            BotUsers usr = data.GetTable <BotUsers>().FirstOrDefault(x => x.TlgUserId == botUsers.TlgUserId);

            if (usr == null)
            {
                data.GetTable <BotUsers>().InsertOnSubmit(botUsers);
                data.SubmitChanges();
                usr = data.GetTable <BotUsers>().FirstOrDefault(x => x.TlgUserId == botUsers.TlgUserId);
            }
            else
            {
                usr           = data.GetTable <BotUsers>().Where(x => x.TlgUserId == botUsers.TlgUserId).ToList()[0];
                usr.LastEnter = DateTime.Now;
                data.SubmitChanges();
            }
            return(usr);
        }
Ejemplo n.º 7
0
        public User RenameUser0(string oldname, string newname)
        {
            //lock (BotUsers)
            {
                oldname = oldname ?? LastUser.UserName;
                oldname = CleanupFromname(oldname);
                string oldkey = KeyFromUsername(oldname);

                newname = newname ?? LastUser.UserName;
                newname = CleanupFromname(newname);
                string newkey = KeyFromUsername(newname);


                User newuser = FindUser(newkey);
                User olduser = FindUser0(oldname);
                if (olduser == null)
                {
                    writeToUserLog("Neigther acct found so creating clean: " + newname);
                    newuser = FindOrCreateUser(newname);
                    newuser.LoadDirectory(GetUserDir(oldkey));
                    return(newuser);
                }

                if (newuser == olduser)
                {
                    writeToUserLog("Same accts found: " + newname);
                    LastUser.UserName = newname;
                    return(newuser);
                }

                if (newuser != null)
                {
                    writeToUserLog("both users exists: " + newname);
                    // remove old acct from dict
                    lock (microBotUsersLock) BotUsers.Remove(oldkey);
                    // grab it into new user
                    SettingsDictionaryReal.AddMissingKeys(olduser.Predicates, newuser.Predicates, ObjectRequester);
                    newuser = olduser;
                    lock (microBotUsersLock) BotUsers[newkey] = newuser;
                    newuser.IsRoleAcct = false;
                    SetupUserWithGraph(newname, newkey, newuser);
                    // rebuild an old one
                    CreateNewUser(oldname, oldkey);
                    newuser = FindOrCreateUser(newname);
                    return(newuser);
                }

                writeToUserLog("Copying old user .. and making new: " + newuser);
                // remove old acct from dict
                lock (microBotUsersLock) BotUsers.Remove(oldkey);
                // grab it into new user
                newuser = olduser;
                lock (microBotUsersLock) BotUsers[newkey] = newuser;
                newuser.IsRoleAcct = false;
                SetupUserWithGraph(newname, newkey, newuser);
                // rebuild an old one
                CreateNewUser(oldname, oldkey);
                return(newuser);


                writeToUserLog("ChangeUser " + oldname + " -> " + newname);

                WriteUserInfo(writeToLog, " olduser='******' ", olduser);
                WriteUserInfo(writeToLog, " newuser='******' ", newuser);

                if (olduser == null)
                {
                    if (newuser == null)
                    {
                        writeToUserLog("Neigther acct found so creating clean: " + newname);
                        newuser = FindOrCreateUser(newname);
                        return(newuser);
                    }
                    if (newuser.IsRoleAcct)
                    {
                        writeToUserLog("User acct IsRole: " + newname);
                        newuser.UserName = newname;
                        return(newuser);
                    }
                    writeToUserLog("User acct found: " + newname);
                    newuser = FindOrCreateUser(newname);
                    return(newuser);
                }

                if (newuser == olduser)
                {
                    writeToUserLog("Same accts found: " + newname);
                    LastUser.UserName = newname;
                    return(newuser);
                }

                // old user existed
                if (newuser != null)
                {
                    if (newuser.IsRoleAcct)
                    {
                        if (olduser.IsRoleAcct)
                        {
                            writeToUserLog(
                                "both acct are RoleAcct .. normaly shouldnt happen but just qa boring switchusers ");
                            return(newuser);
                        }
                        writeToUserLog("New acct is RoleAcct .. so rebuilding: " + newkey);
                        // remove old "new" acct from dict
                        lock (microBotUsersLock) BotUsers.Remove(newkey);
                        // kill its timer!
                        newuser.DisposeObject();
                        newuser = FindOrCreateUser(newname);
                        return(newuser);
                    }
                    else
                    {
                        writeToUserLog("old acct is just some other user so just switching to: " + newname);
                        newuser = FindOrCreateUser(newname);
                        return(newuser);
                    }
                }
                else
                {
                    if (olduser.IsRoleAcct)
                    {
                        writeToUserLog("Copying old RoleAcct .. and making new: " + newuser);
                        // remove old acct from dict
                        lock (microBotUsersLock) BotUsers.Remove(oldkey);
                        // grab it into new user
                        newuser = olduser;
                        lock (microBotUsersLock) BotUsers[newkey] = newuser;
                        newuser.IsRoleAcct = false;
                        SetupUserWithGraph(newname, newkey, newuser);
                        // rebuild an old one
                        CreateNewUser(oldname, oldkey);
                        return(newuser);
                    }
                    else
                    {
                        writeToUserLog("old acct is just some other user so just creating: " + newname);
                        newuser = FindOrCreateUser(newname);
                        return(newuser);
                    }
                }

                writeToUserLog("ERROR, Totally lost so using FindOrCreate and switching to: " + newname);
                newuser = FindOrCreateUser(newname);
                return(newuser);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// registers a new user
        /// </summary>
        /// <param name="duser"></param>
        /// <param name="guildId"></param>
        public void Register(DiscordUser duser, ulong guildId = 0)
        {
            BotUsers buser;

            using (GAFContext context = new GAFContext())
                buser = context.BotUsers.FirstOrDefault(b => (ulong)b.DiscordId.Value == duser.Id);

            if (buser != null)
            {
                if (!buser.IsVerified || guildId == 0)
                {
                    return;
                }

                DiscordGuild  guild  = Program.Client.GetGuildAsync(guildId).Result;
                DiscordMember member = guild.GetMemberAsync(duser.Id).Result;
                DiscordRole   role   = member.Roles.FirstOrDefault(r => r.Id == (ulong)Program.Config.VerifiedRoleId);

                if (role == null)
                {
                    role = guild.GetRole((ulong)Program.Config.VerifiedRoleId);
                    member.GrantRoleAsync(role, "Already verified").Wait();
                }
                else if (role != null && !buser.IsVerified)
                {
                    buser.IsVerified = true;

                    using (GAFContext context = new GAFContext())
                    {
                        context.BotUsers.Update(buser);
                        context.SaveChanges();
                    }
                }
            }

            Logger.Log("MessageHandler: Registering new user " + duser.Username, LogLevel.Trace);

            bool autoVerify = false;

            if (guildId > 0)
            {
                DiscordGuild  guild  = Program.Client.GetGuildAsync(guildId).Result;
                DiscordMember member = guild.GetMemberAsync(duser.Id).Result;
                foreach (DiscordRole role in member.Roles)
                {
                    if (role.Id == (ulong)Program.Config.VerifiedRoleId)
                    {
                        autoVerify = true;
                        break;
                    }
                }
            }

            BotUsers user = new BotUsers()
            {
                DiscordId    = (long)duser.Id,
                AccessLevel  = 0,
                IsVerified   = autoVerify,
                Points       = 0,
                PointsPickEm = 0,
                RegisteredOn = DateTime.UtcNow,
                OsuUsername  = ""
            };

            using (GAFContext context = new GAFContext())
            {
                context.BotUsers.Add(user);
                context.SaveChanges();
            }

            Logger.Log("MessageHandler: User registered", LogLevel.Trace);
        }