# used by several functions for random calls
import random
-# used to match the 'L' at the end of a long int in repr_long
-import re
-
# random_name uses string.strip
import string
# strip any leading quotemark, capitalize and return the name
return string.strip(name, "'").capitalize()
-def repr_long(value):
- string_value = repr(value)
- if re.match('\d*L$', string_value): return string_value.strip("L")
- else: return string_value
-
-def getlong(config, section, option):
- try:
- return int(config.get(section, option).strip("L"))
- except ConfigParser.NoSectionError:
- config.add_section(section)
- return getlong(config, section, option)
- except ConfigParser.NoOptionError:
- setlong(config, section, option, 0)
- return getlong(config, section, option)
-
-def setlong(config, section, option, value):
- return config.set(section, option, repr_long(value))
-
def replace_macros(user, text, is_input=False):
+ """Replaces macros in text output."""
while True:
macro_start = string.find(text, "$(")
if macro_start == -1: break
"""Check for a factor of the current increment count."""
if type(frequency) is str:
frequency = muffconf.getint("time", frequency)
- return not getlong(muffvars.variable_data, "time", "elapsed") % frequency
+ return not muffuniv.universe.internals["counters"].getint("elapsed") % frequency
def on_pulse():
"""The things which should happen on each pulse, aside from reloads."""
# periodically save everything
if check_time("frequency_save"):
- muffvars.save()
for user in muffvars.userlist: user.save()
muffuniv.universe.save()
time.sleep(muffconf.getfloat("time", "increment"))
# increment the elapsed increment counter
- setlong(muffvars.variable_data, "time", "elapsed",
- getlong(muffvars.variable_data, "time", "elapsed") + 1)
+ muffuniv.universe.internals["counters"].set("elapsed", muffuniv.universe.internals["counters"].getint("elapsed") + 1)
def reload_data():
"""Reload data into new persistent objects."""