AttributeError: 'TeleBot' object has no attribute 'chat' - py-telegram-bot-api

I want to create a variable,
message.chat.id outside of function
for example like this
bot = telebot.teleBot("token")
global message
message = bot.message.chat.id
#bot.message_handler(commands=["start"])
def welcome():
bot.send_message(message,"Welcome on here, pls describe yourself")
but the telebot attributes error
does the message argument always have to be inside the function, it can't be outside the function to become a variable?

I think this would be more appropriate code
bot = telebot.teleBot("token")
global message
message = message.chat.id
#bot.message_handler(commands=["start"])
def welcome(message):
global message
bot.send_message(message,"Welcome on here, pls describe yourself")
alternatively just use bot.reply_to(message,"Hello Bros")
you can find the full docs here

Related

Specman e: Is there a way to print unit instance name?

I've built a generic agent that will be instantiated several times in the environment:
unit agent_u {
monitor : monitor_u is instance;
};
The monitor prints some messages, e.g.:
unit monitor_u {
run() is also {
message(LOW, "Hello monitor!");
};
};
I would like to add to the monitor's messages which agent instance has printed them. For example, for environment:
extend sys {
first_agent : agent_u is instance;
second_agent : agent_u is instance;
};
the desirable output will be something like that:
first_agent: Hello monitor!
second_agent: Hello monitor!
I could not find anything related to instance name in the reflection API... Is there some way to print an instance name in e?
Thank you for your help
printing with message() will already include the instance pointer, in your case something like:
[0] agent_u-#1: Hello monitor!
[0] agent_u-#2: Hello monitor!
you can distinguish by these #NUM.
or include "me.e_path()" in your message, which will give the full instance path:
message(LOW, me.e_path(), ": Hello monitor!");
[0] agent_u-#1: sys.first_agent.monitor: Hello monitor!
[0] agent_u-#2: sys.second_agent.monitor: Hello monitor!
Not sure what exactly you refer to by "the instance name", but there are several points to be aware of.
There is the predefined e_path() method of any_unit.
There is a unique identifier for struct and unit instances, consisting of the type name and a unique number, which is returned by to_string() method. This unique identifier is already printed as part of a message.
Moreover, you can use the predefined hook method create_formatted_message(), preferably together with defining your own new message_format, to customize how messages are printed. For example, you might append the result of e_path() to the formatted message string, if you wish it to automatically appear in all messages.
You can also use the short_name() hook to provide your own symbolic names to units, and those will appear in messages instead of the result of to_string().
In principle, you can also override to_string() itself, but that would have more effects than just messages printout.

how to obtain node ID in opnet?

how can I specify node ID in opnet by the use of op_topo_parent ??
I tried many times and the result was this error
<<< Recoverable Error >>>
Object ID (OPC_OBJID_INVALID) is out-of-range.
T (36.4974), EV (483), MOD (top.Office Network.user.wlan_port_rx_0_0), KP (op_topo_parent)
Can anyone give me a simplified example of how to use this function
thanks in advance.
op_topo_parent() needs a child object ID. Based on your error message, you want to find which node encompasses the given receiver(top.Office Network.user.wlan_port_rx_0_0). In order to get the node ID try the following code snippet.
// Get object of current Receiver object
rx_objid = op_id_self();
// Get parent, in this case node, ID
node_objid = op_topo_parent(rx_objid)
I hope this comments help you out.

Excel VBA: using R1C1 format, "Application defined or object defined error"

I am trying to create a formula that references other cells, but I keep getting this "Application defined or object defined error". I use R1C1 convention instead of Offset.
My Code:
Note: This code could be anywhere, I just need it to work. Also, I don't use the code like this. It is used in a reporting tool, but this is just similar code (to what I actually use) sufficient enough to show my problem
Cells(1, 1).Value = "5/1/2014 6:30"
soiDate = "$A$1"
Cells(10, 6).Value = "6/5/2014 14:12"
Cells(10, 10).Formula = "=(R[0]C[-4]-" & soiDate & ")*24" 'Error Occurs Here
UPDATE:
The following does not work either:
Cells(10, 10).FormulaR1C1 = "=(R[0]C[-4]-" & soiDate & ")*24"
Try this:
Cells(10, 10).FormulaR1C1 = _
"=(R[0]C[-4]-" & Range(soiDate).Address(, , xlR1C1) & ")*24"
It errors out since you kinda mixed up R1C1 reference to A1.
Just be consistent, you can use Range Object address property to convert reference. HTH.

How to get current member in a Razor macro

I have asked this question on the Our Umbraco forums, however I wanted to also increase my chances of getting a solution by posting the same question here.
The issue I have is that, inside a Razor macro, I'm unable to get the current Member who is accessing the site. I have tried the following methods:
Calling Member.GetCurrentMember(), but this returns NULL.
Calling Membership.GetUser(), but this returns NULL
Calling UmbracoEnsuredPage.CurrentUser returned NULL;
Is there another way to get the current Member seeing how the above methods do not work in my case?
var m = Membership.GetUser();
That should work, just verified it myself on 4.7.1; it will return NULL if you are not logged in as a member, but when you log in it should get you what you want.
Just a slight change from #E.J.Brennan if the NULL is an issue you can check if you are logged on before trying to GetUser():
if (umbraco.library.IsLoggedOn())
{
m = Membership.GetUser();
}
Starting from v7 you can use the MembershipHelper
#Members.CurrentUserName
#Members.GetCurrentMember()
#Members.GetCurrentMemberId()
Now it's even easier, in the surfaceController you can use just one line:
var member = ApplicationContext.Current.Services.MemberService.GetById(Members.GetCurrentMemberId());
If Members MembershipHElper isn't accessible:
var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
var member = ApplicationContext.Current.Services.MemberService.GetById(memberShipHelper.GetCurrentMemberId());

Perl: how to validate successful call to "XML::eXistDB::RPC"

i am writing a small perl app using the eXist database, and i am wondering is:
how can i see that my call
my $eXist = XML::eXistDB::RPC->new( destination=>$eXist_db, repository=>$bank, user=>"admin", password=>"pass" ) ;
is successful or not ?
thanx
When object initialisation fails, it will be messaged through Log::Report, so hook into that.
This only happens if the programmer to neglected to set either rpc or destination parameter. The new constructor will always return an object instance.
According to the docs:
All methods return a LIST, where the
first scalar is a return code (RC).
When that code is 0, all went well.
Otherwise, the code represent the
transport error or the exception
(refusal) as reported by the server
logic. In either case, the second
scalar in the returned list contains
the error message. For instance,
Maybe this applies also for the constructor, try:
my ($rc,$eXist) = XML::eXistDB::RPC->new( destination=>$eXist_db, repository=>$bank, user=>"admin", password=>"pass" );
now, if $rc != 0 there was an error.