<commit_before>local config = require 'config'
local sidereal = require 'sidereal'
local table = table
local ipairs = ipairs
local print = print

module 'db'


local function format_message(user, msg)
    return 'From: ' .. user .. "\n" .. table.concat(msg, "\n")
end

function post_message(user, msg)
    local DB = sidereal.connect('localhost', 6379)
    DB:rpush("MESSAGES", format_message(user, msg))
end

function message_count()
    local DB = sidereal.connect('localhost', 6379)
    return DB:llen("MESSAGES")
end

function message_read(i)
    local DB = sidereal.connect('localhost', 6379)
    return DB:lindex("MESSAGES", i)
end

function send_to(to, from, msg)
    local DB = sidereal.connect('localhost', 6379)
    DB:lpush("INBOX:" .. to, format_message(from, msg))
end


function register_user(user, password)
    local DB = sidereal.connect('localhost', 6379)
    DB:hset("LOGINS", user, password)
end

function user_exists(user)
    local DB = sidereal.connect('localhost', 6379)
    return DB:hexists("LOGINS", user) == 1
end

function inbox_count(user)
    local DB = sidereal.connect('localhost', 6379)
    return DB:llen("INBOX:" .. user)
end

function read_inbox(user)
    local DB = sidereal.connect('localhost', 6379)
    return DB:lpop("INBOX:" .. user)
end

function auth_user(user, password)
    local DB = sidereal.connect('localhost', 6379)
    local auth = DB:hget("LOGINS", user)
    return auth == password
end
<commit_msg>Turns out it's globals, not sidereal. Duh.<commit_after>local config = require 'config'
local sidereal = require 'sidereal'
local table = table
local ipairs = ipairs
local print = print

module 'db'

local DB = sidereal.connect('localhost', 6379)

local function format_message(user, msg)
    return 'From: ' .. user .. "\n" .. table.concat(msg, "\n")
end

function post_message(user, msg)
    DB:rpush("MESSAGES", format_message(user, msg))
end

function message_count()
    return DB:llen("MESSAGES")
end

function message_read(i)
    return DB:lindex("MESSAGES", i)
end

function send_to(to, from, msg)
    DB:lpush("INBOX:" .. to, format_message(from, msg))
end


function register_user(user, password)
    DB:hset("LOGINS", user, password)
end

function user_exists(user)
    return DB:hexists("LOGINS", user) == 1
end

function inbox_count(user)
    print("INBOX:" .. user)
    return DB:llen("INBOX:" .. user)
end

function read_inbox(user)
    return DB:lpop("INBOX:" .. user)
end

function auth_user(user, password)
    local auth = DB:hget("LOGINS", user)
    return auth == password
end

{'fraction_non_alphanumeric': 0.13445707565660525, 'fraction_numerical': 0.016464131713053703, 'mean_word_length': 4.361344537815126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1733969', 'n_tokens_mistral': 903, 'n_tokens_neox': 843, 'n_words': 236}