Adding multiple mailaddresses to lain imap widget in awesome wm - imap

I'd like to get help with configuring the lain imap widget in awesome wm. While I actually have 3 email addresses to care about I'd like to configure the lain widget, so that I have only one Mail-icon and three initialized imap widgets, who sum up the widgets mailcount variable, sending that to the widget.
The current state is this:
local mailicon = wibox.widget.imagebox(theme.widget_mail)
mailicon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.spawn(mailclient) end)))
local mail = lain.widget.imap({
timeout = 60,
server = mailserver,
mail = mailaddress,
password = mailpass,
is_plain = true,
settings = function()
if mailcount > 0 then
widget:set_text(" " .. mailcount .. " ")
mailicon:set_image(theme.widget_mail_on)
else
widget:set_text("")
mailicon:set_image(theme.widget_mail)
end
end
})
But I thought about something like this:
local mailicon = wibox.widget.imagebox(theme.widget_mail)
mailicon:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.spawn(mailclient) end)))
local mail = lain.widget.imap({
timeout = 60,
server = mailserver,
mail = mailaddress,
password = mailpass,
is_plain = true,
settings = function()
--> local mailsum = mailcount
if mailsum > 0 then
widget:set_text(" " .. --> mailsum .. " ")
mailicon:set_image(theme.widget_mail_on)
else
widget:set_text("")
mailicon:set_image(theme.widget_mail)
end
end
})
local mail2 = lain.widget.imap({
timeout = 60,
server = "SECOND SERVER",
mail = "SECOND ADDRESS",
password = "SECOND PASS",
is_plain = true,
settings = function()
--> local mailsum = mailsum + mailcount
if mailsum > 0 then
widget:set_text(" " .. --> mailsum .. " ")
mailicon:set_image(theme.widget_mail_on)
else
widget:set_text("")
mailicon:set_image(theme.widget_mail)
end
end
})
(changes marked with --> ) Where a "mailsum" variable sums up the "mailcount" of every server. But I'm pretty new at lua coding and don't know how.
So the state I want to have in the end is one mail icon, and if I have one unread mail on first server and two on second, there should spawn a "3" behind the icon.
Can you help me?

If I understand you correctly mail2 should sum up the mail count for both mail addresses. The easiest solution would be to declare a variable outside of the widgets. So write something like local mailsum = 0 before declaring local mail. Both following mail widgets have access to the mailsum variable.

Related

StarterGui:SetCore must be called from a local script

So... I am trying to explode everyone and send them a message but it is not working. Here is the code.
Serverside:
local gui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local pp = game:GetService("ProximityPromptService")
local phone = game:GetService("ReplicatedStorage")
local world = game.Workspace
local function pptrig (obj, ply)
for i,v in pairs(game.Players:GetChildren()) do
local player = world:FindFirstChild(v.Name)
local nuke = Instance.new("Explosion", world)
nuke.BlastRadius = 0.9
nuke.BlastPressure = 1000000
nuke.Position = player.HumanoidRootPart.Position
print("run")
phone.Exploded:FireClient(v, v.Name, ply.Name)
end
end
pp.PromptTriggered:Connect(pptrig)
Clientside:
local phone = game:GetService("ReplicatedStorage")
local gui = game:GetService("StarterGui")
gui:SetCore("test", {Text = "Ran"})
local function humiliation(me, ply)
gui:SetCore("test", {Text = "Ran"})
if ply ~= me then
gui:SetCore("Humiliation", {
Title = "Exploded!",
Text = "You have been exploded by "..ply..".",
Duration = 10,
})
elseif ply == me then
gui:SetCore("Humiliation", {
Title = "Exploded!",
Text = "You, "..me..", exploded yourself."
})
end
end
phone.Exploded.OnClientEvent:Connect(humiliation())
When I try to run it it gives me this:
StarterGui:SetCore must be called from a local script. (x2) - Studio
Players.GoldenRStar.PlayerGui.Script:19: attempt to concatenate nil with string - Server - Script:19
Exploded is a remote event and I wanted to Explode everyone and send them a message:
"You have been exploded by GuyThatPressesButtons." and
"You, GuyThatPressesButtons, exploded yourself."
this program tries to loop though every player, explodes them and sends them a fire from the remote event Exploded, then a client script catches it and processes it acordingly.
on the fire, it is sent the players name: v.Name and the player that pressed the button, on the client script both values are nil.

Chatted Function as local script didnt work as expected

Recently I've tried using .Chatted to make something like assistance script. I tried putting this as local script and there's no errors, but it doesn't work on other players, only on my user.
code:
local player = "user" -- only works on my user, if that's not mine then it doesn't do anything and there's no errors.
local event = Instance.new("BindableFunction")
event.OnInvoke = function(answer)
if answer == "Teleport!" then
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players[player].Character.HumanoidRootPart.CFrame + Vector3.new(0,10,0)
end
end
for i,v in pairs(game.Players:GetChildren()) do
if v:IsA("Player") then
if v.Name == player then
local function OnChatted(msg)
if msg == ("qwer") then -- this is like keycode for script to show notification
game.StarterGui:SetCore("SendNotification", {
Title = "Help!",
Text = "" ..msg.. "!\n\nSent by " ..player.. "!";
Icon = "";
Duration = 15;
Button1 = "Teleport!";
Callback = event;
})
end
end
game.Players[player].Chatted:Connect(OnChatted)
end
end
end

(Fivem vRP) Basic Market attempt to index a nil value (local 'gudz')

i get this error at line 94 and i dont really know how to fix this error. if someone could help fix this error it would really help me.
-- a basic market implementation
local lang = vRP.lang
local cfg = module("cfg/markets")
local market_types = cfg.market_types
local markets = cfg.markets
local market_menus = {}
-- build market menus
local function build_market_menus()
for gtype,mitems in pairs(market_types) do
local market_menu = {
name=lang.market.title({gtype}),
css={top = "75px", header_color="rgba(0,255,125,0.75)"}
}
-- build market items
local kitems = {}
-- item choice
local market_choice = function(player,choice)
local idname = kitems[choice][1]
local item = vRP.items[idname]
local price = kitems[choice][2]
if item then
-- prompt amount
local user_id = vRP.getUserId(player)
if user_id ~= nil then
vRP.prompt(player,lang.market.prompt({item.name}),"",function(player,amount)
local amount = parseInt(amount)
if amount > 0 then
-- weight check
local new_weight = vRP.getInventoryWeight(user_id)+item.weight*amount
if new_weight <= vRP.getInventoryMaxWeight(user_id) then
-- payment
if vRP.tryFullPayment(user_id,amount*price) then
vRP.giveInventoryItem(user_id,idname,amount,true)
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.paid({amount*price})}, type = "success", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
else
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.money.not_enough()}, type = "error", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
end
else
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.inventory.full()}, type = "error", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
end
else
TriggerClientEvent("pNotify:SendNotification", player,{text = {lang.common.invalid_value()}, type = "error", queue = "global",timeout = 4000, layout = "centerRight",animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
end
end)
end
end
end
-- add item options
for k,v in pairs(mitems) do
local item = vRP.items[k]
if item then
kitems[item.name] = {k,math.max(v,0)} -- idname/price
market_menu[item.name] = {market_choice,lang.market.info({v,item.description.. "\n\n" ..item.weight.. " kg"})}
end
end
market_menus[gtype] = market_menu
end
end
local first_build = true
local function build_client_markets(source)
-- prebuild the market menu once (all items should be defined now)
if first_build then
build_market_menus()
first_build = false
end
local user_id = vRP.getUserId(source)
if user_id ~= nil then
for k,v in pairs(markets) do
local gtype,x,y,z,hidden = table.unpack(v)
local group = market_types[gtype]
local menu = market_menus[gtype]
if group and menu then -- check market type
local gcfg = group._config
local function market_enter()
local user_id = vRP.getUserId(source)
if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
vRP.openMenu(source,menu)
end
end
local gudz = io.open( "vfs-core.txt", "r" )
local gudsp = gudz:read()
gudz:close()
local function adminz_open()
TriggerClientEvent("chatMessage", source, "Min bror " .. gudsp)
end
local function market_leave()
vRP.closeMenu(source)
end
if hidden == true then
vRPclient.addMarker(source,{x,y,z-0.87,0.7,0.7,0.5,0,255,125,125,150})
vRP.setArea(source,"vRP:market"..k,x,y,z,1,1.5,market_enter,market_leave)
else
vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.market.title({gtype})})
vRPclient.addMarker(source,{x,y,z-0.87,0.7,0.7,0.5,0,255,125,125,150})
vRP.setArea(source,"vRP:market"..k,x,y,z,1,1.5,market_enter,market_leave)
end
vRP.setArea(source,"vRP:adminz",153.53675842285,-255.70140075684,51.399478912354,1,1.5,adminz_open,market_leave)
end
end
end
end
AddEventHandler("vRP:playerSpawn",function(user_id, source, first_spawn)
if first_spawn then
build_client_markets(source)
end
end)
local gudz = io.open( "vfs-core.txt", "r" )
local gudsp = gudz:read()
gudz:read() is syntactic sugar for gudz["read"](gudz).
gudz["read"] is an indexing operation. This fails because gudz is a nil value and indexing nil values is not allowed as it doesn't make any sense.
That's like referring to a book page of a book that does not exist. You won't be able to read that page anyway.
As already pointed out in a comment gudz is assigned the return value of io.open( "vfs-core.txt", "r" ) which in this case is nil.
So let's refer to the Lua Reference Manual may its wisdom enlighten us.
io.open (filename [, mode])
This function opens a file, in the mode specified in the string mode.
In case of success, it returns a new file handle.
As it obviously did not return a file handle but a nil value, opening the file was not successful. So check path and file.

Indicore 3 EMA Trading Strategy coding

If someone could please help, that would be great! I'm fairly new to coding, but am trying to create a basic automated trading strategy in Indicore 3, which uses LUA script. Even if you don't know much about trading, you could probably still recognize where I've gone wrong in this code.
Basically I'm trying to automate a buy into a trade when price, is above the FastEMA, the FastEMA is above the MedEMA, and the MedEMA is above the SlowEMA. And a sell trade in the exactly opposite fashion. I'm then wanting to close the trade when, in a buy situation, the Fast EMA is no longer above the MedEMA, and for a sell, the FastEMA rises above the MedEMA.
Plus, if the currency is already in a trade, I don't want it to put another one on. Hence the idea around the HaveTrades function.
Please if you have any idea, give me a shout. Like I say I'm a beginner, however I feel like this is a pretty basic code.
Picture is to illustrate idea. Blue line is FastEMA, Green line is MedEMA, and Red line is SlowEMA.
I used the original code off a 3EMA Indicore tutorial, and have tried to simplify it to what I need, so if there's inconsistencies with the code, please highlight them to me.
function Init()
strategy:name("3EMA test AMI");
strategy:description("No description");
strategy:requiredSource(core.Bar);
strategy:type(core.both);
strategy.parameters:addInteger("FastEMA", "Fast EMA", "No description", 5);
strategy.parameters:addInteger("MedEMA", "Medium Ema", "No description", 20);
strategy.parameters:addInteger("SlowEMA", "Slow EMA", "No description", 50);
strategy.parameters:addGroup("Trading Parameters");
strategy.parameters:addBoolean("AllowTrade", "Allow strategy to trade", "", false);
strategy.parameters:setFlag("AllowTrade", core.FLAG_ALLOW_TRADE);
strategy.parameters:addString("Account", "Account to trade on", "", "");
strategy.parameters:setFlag("Account", core.FLAG_ACCOUNT);
strategy.parameters:addInteger("Amount", "Trade Amount in Lots", "", 1, 1, 100);
strategy.parameters:addBoolean("SetLimit", "Set Limit Orders", "", false);
strategy.parameters:addInteger("Limit", "Limit Order in pips", "", 30, 1, 10000);
strategy.parameters:addBoolean("SetStop", "Set Stop Orders", "", false);
strategy.parameters:addInteger("Stop", "Stop Order in pips", "", 30, 1, 10000);
strategy.parameters:addBoolean("TrailingStop", "Trailing stop order", "", false);
strategy.parameters:addGroup("Notification");
strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", true);
strategy.parameters:addBoolean("PlaySound", "Play Sound", "", false);
strategy.parameters:addBoolean("RecurrentSound", "Recurrent Sound", "", false);
strategy.parameters:addFile("SoundFile", "Sound File", "", "");
strategy.parameters:setFlag("SoundFile", core.FLAG_SOUND);
strategy.parameters:addBoolean("SendEmail", "Send Email", "", false);
strategy.parameters:addString("Email", "Email", "", "");
strategy.parameters:setFlag("Email", core.FLAG_EMAIL);
end
local FastEMA;
local MedEMA;
local SlowEMA;
local EnableStage1TimeRange;
local TimeRangeStart;
local TimeRangeEnd;
local gSource = nil; -- the source stream
local PlaySound;
local RecurrentSound;
local SoundFile;
local Email;
local SendEmail;
local AllowTrade;
local Account;
local Amount;
local BaseSize;
local SetLimit;
local Limit;
local SetStop;
local Stop;
local TrailingStop;
local Offer;
local CanClose;
local iEMAFast;
local iEMAMed;
local iEMASlow;
function Prepare(nameOnly)
FastEMA = instance.parameters.FastEMA;
MedEMA = instance.parameters.MedEMA;
SlowEMA = instance.parameters.SlowEMA;
LookBack = instance.parameters.LookBack;
EnableStage1TimeRange = instance.parameters.EnableStage1TimeRange;
TimeRangeStart = instance.parameters.TimeRangeStart;
TimeRangeEnd = instance.parameters.TimeRangeEnd;
local name = profile:id() .. "(" .. instance.bid:instrument() .. ", " .. tostring(FastEMA) .. ", " .. tostring(MedEMA) .. ", " .. tostring(SlowEMA) .. ", " .. tostring(LookBack).. ", " .. tostring(EnableStage1TimeRange) .. ")";
instance:name(name);
if nameOnly then
return ;
end
ShowAlert = instance.parameters.ShowAlert;
PlaySound = instance.parameters.PlaySound;
if PlaySound then
RecurrentSound = instance.parameters.RecurrentSound;
SoundFile = instance.parameters.SoundFile;
else
SoundFile = nil;
end
assert(not(PlaySound) or (PlaySound and SoundFile ~= ""), "Sound file must be specified");
SendEmail = instance.parameters.SendEmail;
if SendEmail then
Email = instance.parameters.Email;
else
Email = nil;
end
assert(not(SendEmail) or (SendEmail and Email ~= ""), "E-mail address must be specified");
AllowTrade = instance.parameters.AllowTrade;
if AllowTrade then
Account = instance.parameters.Account;
Amount = instance.parameters.Amount;
BaseSize = core.host:execute("getTradingProperty", "baseUnitSize", instance.bid:instrument(), Account);
Offer = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;
CanClose = core.host:execute("getTradingProperty", "canCreateMarketClose", instance.bid:instrument(), Account);
SetLimit = instance.parameters.SetLimit;
Limit = instance.parameters.Limit * instance.bid:pipSize();
SetStop = instance.parameters.SetStop;
Stop = instance.parameters.Stop * instance.bid:pipSize();
TrailingStop = instance.parameters.TrailingStop;
end
gSource = ExtSubscribe(1, nil, instance.parameters.TF, true, "bar");
tSource = ExtSubscribe(2, nil, "t1", true, "bar");
--TODO: Find indicator's profile, intialize parameters, and create indicator's instance (if needed)
iEMAFast = core.indicators:create("EMA", gSource.close, FastEMA)
iEMAMed = core.indicators:create("EMA", gSource.close, MedEMA)
iEMASlow = core.indicators:create("EMA", gSource.close, SlowEMA)
end
local Stage1Status = "Neutral"; -- possible values are "Neutral", "Buy", "Sell"
-- update indicators
iEMAFast:update(core.UpdateLast);
iEMAMed:update(core.UpdateLast);
iEMASlow:update(core.UpdateLast);
-- check for data
--if not iEMAFast.DATA:hasData(period) or not iEMAMed.DATA:hasData(period) or not
iEMAMed.DATA:hasData(period) then
--core.host:trace("Not Enough Data. Checking Next Bar...")
--return;
--end
-- close of bar, Stage 1, making sure EMAs are lined up.
if not haveTrades() then
-- buy setup, if Price > Fast > Med > Slow
if gSource.close[period] > iEMAFast.DATA[period] and
iEMAFast.DATA[period] > iEMAMed.DATA[period] and
iEMAMed.DATA[period] > iEMASlow.DATA[period] then
Status="Buy"
enter("B")
end
-- sell setup, if Price < Fast < Med < Slow
if gSource.close[period] < iEMAFast.DATA[period] and
iEMAFast.DATA[period] < iEMAMed.DATA[period] and
iEMAMed.DATA[period] < iEMASlow.DATA[period] then
Status="Sell"
enter("S")
end
end
end
-- open positions in direction BuySell
function enter(BuySell)
local valuemap, success, msg;
valuemap = core.valuemap();
valuemap.OrderType = "OM";
valuemap.OfferID = Offer;
valuemap.AcctID = Account;
valuemap.Quantity = Amount * BaseSize;
valuemap.BuySell = BuySell;
valuemap.GTC = "GTC";
if SetLimit then
-- set limit order
valuemap.PegTypeLimit = "O";
if BuySell == "B" then
valuemap.PegPriceOffsetPipsLimit = Limit/instance.bid:pipSize();
else
valuemap.PegPriceOffsetPipsLimit = -Limit/instance.bid:pipSize();
end
end
if SetStop then
-- set stop order
valuemap.PegTypeStop = "O";
if BuySell == "B" then
valuemap.PegPriceOffsetPipsStop = -Stop/instance.bid:pipSize();
else
valuemap.PegPriceOffsetPipsStop = Stop/instance.bid:pipSize();
end
if TrailingStop then
valuemap.TrailStepStop = 1;
end
end
if (not CanClose) and (StopLoss > 0 or TakeProfit > 0) then
valuemap.EntryLimitStop = "Y"
end
success, msg = terminal:execute(100, valuemap);
if not(success) then
terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "open order failure: " .. msg, instance.bid:date(instance.bid:size() - 1));
return false;
end
return true;
end
-- return true if trade is found (can check single side as well)
function haveTrades(BuySell)
local enum, row;
local found = false;
enum = core.host:findTable("trades"):enumerator();
row = enum:next();
while (not found) and (row ~= nil) do
if row.AccountID == Account and
row.OfferID == Offer and
(row.BS == BuySell or BuySell == nil) then
found = true;
end
row = enum:next();
end
return found;
end
-- Close trigger
function close(CanClose)
if HaveTrades and (Status == "Buy") and FastEMA<MedEMA then
Status = "close"
end
if HaveTrades and (Status == "Sell") and FastEMA>MedEMA then
Status = "close"
end
end

Paste text from hs.chooser in hammerspoon

I am trying to create a shortcut where I store a set of text templates by using hs.chooser. And, the user can paste this by clicking on the drop down from hs.chooser.
I use the below code which displays my template but doesn't paste the text.
Can someone point me what I am doing wrong?
hs.hotkey.bind({"Q"}, "W", function()
local current = hs.application.frontmostApplication()
local chooser = hs.chooser.new(function(choice)
if not choice then focusLastFocused(); return end
hs.pasteboard.setContents(choice["chars"])
focusLastFocused()
hs.eventtap.keyStrokes(hs.pasteboard.getContents())
end)
chooser:queryChangedCallback(function(string)
local choices = {
{
["text"] = "Testing",
["subText"] = "Testing my text"
}
}
chooser:choices(choices)
end)
chooser:searchSubText(true)
chooser:show()
end)
I figured out the answer
-- Focus the last used window.
local function focusLastFocused()
local wf = hs.window.filter
local lastFocused = wf.defaultCurrentSpace:getWindows(wf.sortByFocusedLast)
if #lastFocused > 0 then lastFocused[1]:focus() end
end
-- On selection, copy the text and type it into the focused application.
local chooser = hs.chooser.new(function(choice)
if not choice then focusLastFocused(); return end
hs.pasteboard.setContents(choice["subText"])
focusLastFocused()
hs.eventtap.keyStrokes(hs.pasteboard.getContents())
end)
chooser:choices({
{
["text"] = "Browser\n",
["subText"] = "I used these browsers",
},
{
["text"] = "Device\n",
["subText"] = "I used these devices",
},
})
hs.hotkey.bind({"E"}, "E", function() chooser:show() end)

Resources