Skip to content

Commit 012153d

Browse files
committed
Initial commit
1 parent 55abae5 commit 012153d

21 files changed

+1217
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ ENV/
8787

8888
# Rope project settings
8989
.ropeproject
90+
91+
\.remote-sync\.json

.pylintrc

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
[MASTER]
2+
3+
# Python code to execute, usually for sys.path manipulation such as
4+
# pygtk.require().
5+
6+
# gen-py module has to be added manually since it's generated using maxskins,
7+
# thus pylint does not know where gen-py module is located.
8+
# For this to work properly
9+
# pylint has to be called from directory: example/*/client/py.
10+
init-hook='import sys; sys.path.append("gen-py")'
11+
12+
[REPORTS]
13+
14+
# Set the output format. Available formats are text, parseable, colorized, msvs
15+
# (visual studio) and html. You can also give a reporter class, eg
16+
# mypackage.mymodule.MyReporterClass.
17+
output-format=colorized
18+
19+
[FORMAT]
20+
21+
function-rgx=[a-zA_][a-zA-Z0-9_]{2,70}$
22+
method-rgx=[a-z_][a-zA-Z0-9_]{2,70}$
23+
24+
# Maximum number of characters on a single line.
25+
max-line-length=200
26+
27+
28+
[TYPECHECK]
29+
30+
# List of module names for which member attributes should not be checked
31+
# (useful for modules/projects where namespaces are manipulated during runtime
32+
# and thus existing member attributes cannot be deduced by static analysis
33+
ignored-modules=
34+
35+
ignored-classes=
36+
37+
generated-members=commit,query,add,delete,run
38+
39+
[MISCELLANEOUS]
40+
41+
# List of note tags to take in consideration, separated by a comma.
42+
#notes=FIXME,TODO
43+
notes=
44+
45+
good-names=i,j,x,y,id
46+
47+
[DESIGN]
48+
49+
# Maximum number of arguments for function / method
50+
max-args=5
51+
52+
# Argument names that match this expression will be ignored. Default to name
53+
# with leading underscore
54+
ignored-argument-names=_.*
55+
56+
# Maximum number of locals for function / method body
57+
max-locals=60
58+
59+
# Maximum number of return / yield for function / method body
60+
max-returns=6
61+
62+
# Maximum number of branch for function / method body
63+
max-branches=12
64+
65+
# Maximum number of statements in function / method body
66+
max-statements=150
67+
68+
# Maximum number of parents for a class (see R0901).
69+
max-parents=7
70+
71+
# Maximum number of attributes for a class (see R0902).
72+
max-attributes=7
73+
74+
# Minimum number of public methods for a class (see R0903).
75+
min-public-methods=2
76+
77+
# Maximum number of public methods for a class (see R0904).
78+
max-public-methods=100
79+
80+
# Maximum number of boolean expressions in a if statement
81+
max-bool-expr=5
82+
83+
84+
[MESSAGES CONTROL]
85+
86+
# Enable the message, report, category or checker with the given id(s). You can
87+
# either give multiple identifier separated by comma (,) or put this option
88+
# multiple time.
89+
#enable=
90+
91+
# Disable the message, report, category or checker with the given id(s). You
92+
# can either give multiple identifier separated by comma (,) or put this option
93+
# multiple time (only on the command line, not in the configuration file where
94+
# it should appear only once).
95+
disable=empty-docstring,broad-except,abstract-method,no-self-use,bad-continuation

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# foe-bot
2-
A simple bot to do automate the main functions of FoE
1+
# FoE-Bot

__init__.py

Whitespace-only changes.

foe/__init__.py

Whitespace-only changes.

foe/config.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
"""
3+
"""
4+
5+
# Native
6+
import os
7+
8+
# 3rd-Party
9+
import anyconfig
10+
11+
# Proprietary
12+
13+
14+
DEFAULT = './config/foe.yml'
15+
# Add the ability to get config from a different file
16+
PATH = os.environ.get('FOE_CONFIG', DEFAULT)
17+
# Load the default config then override, so that we always have the correct structure
18+
config = anyconfig.load([DEFAULT, PATH])

foe/config/foe.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
game:
3+
version: 1.98
4+
server: en9
5+
secret: bTsZ5/8lOyt2Nfqb8qhBDIildUIzz842pzNidXIL6/ytDWSRdtWbuC7upEcwCc/k6cuXDOppjOK/gudECEUTYQ==
6+
timestamp: 1491392992
7+
8+
login:
9+
user_key: '***'
10+
sid: '***'

foe/db.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
"""
3+
"""
4+
5+
# Native
6+
import os
7+
import time
8+
from contextlib import contextmanager
9+
10+
# 3rd-Party
11+
from sqlalchemy import create_engine, MetaData
12+
from sqlalchemy.orm import sessionmaker, scoped_session
13+
14+
# Proprietary
15+
from models.model import Model, Base
16+
17+
18+
engine = create_engine('sqlite:///foe.db')
19+
20+
21+
session = scoped_session(sessionmaker(autocommit=False, bind=engine))
22+
23+
def init():
24+
"""
25+
Initalizes the database, creating all the required tables
26+
"""
27+
28+
Base.metadata.create_all(bind=engine)
29+
30+
def exists():
31+
"""
32+
Returns True if the database has been setup (contains tables)
33+
"""
34+
35+
meta = MetaData(engine)
36+
meta.reflect()
37+
38+
return bool(meta.tables)
39+
40+
def delete():
41+
"""
42+
Deletes all data from the database
43+
"""
44+
45+
meta = MetaData(engine)
46+
meta.reflect()
47+
48+
for table in reversed(meta.sorted_tables):
49+
engine.execute(table.delete())
50+
51+
def tables():
52+
"""
53+
Returns a dict of all the tables in the database
54+
"""
55+
56+
meta = MetaData(engine)
57+
meta.reflect()
58+
59+
return meta.tables
60+
61+
def drop():
62+
"""
63+
Drops the database, essentially wiping it clean of data and tables
64+
"""
65+
66+
# Fetches the meta data (tables/schema/etc) from the database and then drops it that way,
67+
# rather than getting the meta data from the python classes which could leave things around
68+
# Or: https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/DropEverything
69+
meta = MetaData(engine)
70+
meta.reflect()
71+
meta.drop_all()

foe/deploy.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
"""
3+
"""
4+
5+
# Native
6+
import random
7+
import time
8+
9+
# 3rd-Party
10+
11+
# Proprietary
12+
import db
13+
14+
session = db.session
15+
16+
db.drop()
17+
print "Deploy: Dropped database"
18+
19+
db.init()
20+
print "Deploy: Initialized database"
21+
22+
start = time.time()
23+
24+
print "Deploy: Committing to database..."
25+
26+
session.commit()
27+
28+
print "Deploy: Committed to database in %s" % (time.time() - start)

foe/main.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
"""
3+
"""
4+
5+
#
6+
import time
7+
import random
8+
9+
#
10+
11+
#
12+
from models.account import Account
13+
from models.tavern import Tavern
14+
15+
import deploy
16+
17+
from db import session
18+
19+
20+
account = Account()
21+
22+
session.add(account)
23+
24+
count = 0
25+
26+
refresh = random.randrange(5 * 60, 30 * 60)
27+
28+
while True:
29+
30+
if not count or count >= refresh:
31+
account.fetch()
32+
33+
print "Players: %s" % (len(account.players))
34+
35+
print "Buildings: %s" % (len(account.city.buildings))
36+
37+
print "Taverns: %s" % (len(account.taverns))
38+
39+
for tavern in account.taverns:
40+
tavern.sit()
41+
#
42+
for player in account.players:
43+
player.aid()
44+
45+
Tavern.collect()
46+
47+
session.commit()
48+
49+
refresh = count + random.randrange(5 * 60, 30 * 60)
50+
51+
print "Checking... (%s)" % (count)
52+
53+
for building in account.city.buildings:
54+
building.pickup()
55+
56+
for building in account.city.buildings:
57+
building.produce()
58+
59+
session.commit()
60+
61+
sleep = random.randrange(10, 30)
62+
63+
time.sleep(sleep)
64+
65+
count += sleep

foe/models/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)