Debian Codegraph @

python/guilds/guildoracle.py

raw
1 # Script for say event of guild member board
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 #
17 # authors: majorwoo [email protected], Avion [email protected]
18
19
20 import Crossfire
21 import CFGuilds
22 import CFLog
23
24 import sys
25 import string
26 from CFGuildClearance import CheckClearance
27
28 activator=Crossfire.WhoIsActivator()
29 activatorname=activator.Name
30 whoami=Crossfire.WhoAmI()
31 isDM=activator.DungeonMaster
32 mymap=activator.Map
33 log=CFLog.CFLog()
34 guildname=Crossfire.ScriptParameters() # 6 is say eventC fi
35 if CheckClearance([guildname,"GuildMaster"],activator):
36 guild=CFGuilds.CFGuild(guildname)
37 guildrecord=CFGuilds.CFGuildHouses().info(guildname)
38 Approved = 'Access granted'
39 else:
40 Approved = 'Access denied'
41
42 Access = 0
43
44 if (Approved == 'Access granted'):
45 Access = 1
46 else:
47 whoami.Say(Approved)
48
49 if (Access ==1) or (isDM == 1):
50 if (guildname):
51 guild = CFGuilds.CFGuild(guildname)
52 guildhouse = CFGuilds.CFGuildHouses()
53 text = string.split(Crossfire.WhatIsMessage())
54 if guild.info(activatorname) == 0 and isDM == 0:
55 message = 'You don\'t belong to this guild!'
56 elif text[0] == 'help' or text[0] == 'yes':
57 if isDM:
58 message = '\nList of commands:\n-list\n-add <name>\n-remove <member>\n-info <member>\n-promote <member>\n-demote <member>\n-status <member> <status>\n-guildstatus <status>'
59 else:
60 message='\nList of commands:\n-list\n-remove <member>\n-info <member>\n-promote <member>\n-demote <member>\n-status <member> <status>'
61 elif text[0] == 'info':
62 if len(text)==2:
63 record = guild.info(text[1])
64 if record:
65 message = 'Information for %s:\n' %text[1]
66 message += 'Rank: %s\n'%record['Rank']
67 message += 'Status: %s\n'%record['Status']
68 message += 'Join date: %s\n'%record['Join_date']
69 if record['Demerits'] != '0':
70 message += 'Demerits: %s\n'%record['Demerits']
71 if record['Dues'] != '0':
72 message += 'Paid dues: %s\n'%Crossfire.CostStringFromValue(long(record['Dues']))
73 else:
74 message = '%s is not a member' %text[1]
75 else:
76 message = 'Usage "info <member_name>"'
77
78 elif text[0] == 'remove':
79 if len(text)==2:
80 if guild.info(text[1]):
81 message = 'Removed %s from the guild' %text[1]
82 guild.remove_member(text[1])
83 else:
84 message = '%s was not a member' %text[1]
85 else:
86 message = 'Usage "remove <member_name>"'
87 elif text[0] == 'list':
88 Crossfire.SetPlayerMessage('Who are the members?', 2)
89 list = guild.list_members()
90
91 message = '\nList of members:\n'
92 for member in list:
93 message += '%s (%s)\n'%(member, guild.info(member)['Rank'])
94 message += 'Total members = ' + str(len(list))
95
96 elif text[0] == 'promote':
97 if len(text)==2:
98 record = guild.info(text[1])
99 if record:
100 if guild.promote_member(text[1]):
101 record = guild.info(text[1]) #refresh record
102 message = '%s promoted to %s' %(text[1], record['Rank'])
103 else:
104 message = 'You cannot promote %s' %text[1]
105 else:
106 message = '%s is not a member' %text[1]
107 else:
108 message = 'Usage "promote <member_name>"'
109 elif text[0] == 'demote':
110 if len(text)==2:
111 record = guild.info(text[1])
112 if record:
113 if guild.demote_member(text[1]):
114 record = guild.info(text[1]) #refresh record
115 message = '%s demoted to %s' %(text[1], record['Rank'])
116 else:
117 message = 'You cannot demote %s' %text[1]
118 else:
119 message = '%s is not a member' %text[1]
120 else:
121 message = 'Usage "demote <member_name>"'
122 elif text[0] == 'status':
123 record = guild.info(text[1])
124 if record:
125 if len(text)==3:
126 if guild.change_status(text[1],text[2]):
127 record = guild.info(text[1]) #refresh record
128 message = '%s now has status of %s' %(text[1], record['Status'])
129 else:
130 status = ', '.join(guild.status)
131 message = '%s is not a valid status, valid values are %s.' %(text[2],status)
132 else:
133 status = ', '.join(guild.status)
134 message = 'Current status for %s is %s.\nTo change use "status %s <status>" where status is one of %s.' %(text[1],record['Status'],text[1],status)
135 else:
136 message = '%s is not a member' %text[1]
137 elif text[0] == 'add' and isDM:
138 if len(text)==2:
139 if log.info(text[1]):
140 if guild.info(text[1]):
141 message = '%s is already a member.' %text[1]
142 else:
143 #changed to support python 2.5 guild.add_member(text[1], 'Initiate' if len(text)==2 else text[2])
144 guild.add_member(text[1], 'Initiate' )
145 message = 'Added %s to the guild' %text[1]
146 else:
147 message = 'Sorry, I don\'t know any %s' %text[1]
148 else:
149 message = 'Usage "add <membername>"'
150 elif text[0] == 'guildstatus' and isDM:
151 record = guildhouse.info(guildname)
152 if len(text)==2:
153 if record:
154 if guildhouse.change_status(guildname,text[1]):
155 record = guildhouse.info(text[1]) #refresh record
156 message = '%s now has status of %s' %(guildname, record['Status'])
157 else:
158 message = '%s is not a valid status' %text[1]
159 else:
160 message = '%s is not a guild' %guildname
161 else:
162 status = ", ".join(guildhouse.status)
163 message = 'Current guild status is %s.\nTo change it use "guildstatus <status>" where status is one of %s' %(str(record['Status']),status)
164 else:
165 message = 'What did you need?'
166 else:
167 message = 'Board Error'
168 whoami.Say(message)